Skip to content

Commit 5f09e4a

Browse files
authored
feat: add EPSILON parameter support to VSIM command (#3041)
1 parent d8e14fa commit 5f09e4a

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

packages/client/lib/commands/VSIM.spec.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ describe('VSIM', () => {
3131
FILTER: '.price > 20',
3232
'FILTER-EF': 50,
3333
TRUTH: true,
34-
NOTHREAD: true
34+
NOTHREAD: true,
35+
EPSILON: 0.1
3536
});
3637
assert.deepEqual(
3738
parser.redisArgs,
3839
[
39-
'VSIM', 'key', 'ELE', 'element',
40-
'COUNT', '5', 'EF', '100', 'FILTER', '.price > 20',
41-
'FILTER-EF', '50', 'TRUTH', 'NOTHREAD'
40+
'VSIM', 'key', 'ELE', 'element', 'COUNT', '5',
41+
'EPSILON', '0.1', 'EF', '100', 'FILTER', '.price > 20',
42+
'FILTER-EF', '50', 'TRUTH', 'NOTHREAD',
4243
]
4344
);
4445
});
@@ -56,6 +57,27 @@ describe('VSIM', () => {
5657
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 0] }
5758
});
5859

60+
61+
testUtils.testAll('vSim with options', async client => {
62+
await client.vAdd('key', [1.0, 2.0, 3.0], 'element1');
63+
await client.vAdd('key', [1.1, 2.1, 3.1], 'element2');
64+
65+
const result = await client.vSim('key', 'element1', {
66+
EPSILON: 0.1,
67+
COUNT: 1,
68+
EF: 100,
69+
FILTER: '.year == 8',
70+
'FILTER-EF': 50,
71+
TRUTH: true,
72+
NOTHREAD: true
73+
});
74+
75+
assert.ok(Array.isArray(result));
76+
}, {
77+
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 0] },
78+
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 0] }
79+
});
80+
5981
testUtils.testWithClient('vSim with RESP3', async client => {
6082
await client.vAdd('resp3-key', [1.0, 2.0, 3.0], 'element1');
6183
await client.vAdd('resp3-key', [1.1, 2.1, 3.1], 'element2');

packages/client/lib/commands/VSIM.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { transformDoubleArgument } from './generic-transformers';
44

55
export interface VSimOptions {
66
COUNT?: number;
7+
EPSILON?: number;
78
EF?: number;
89
FILTER?: string;
910
'FILTER-EF'?: number;
@@ -44,6 +45,10 @@ export default {
4445
parser.push('COUNT', options.COUNT.toString());
4546
}
4647

48+
if (options?.EPSILON !== undefined) {
49+
parser.push('EPSILON', options.EPSILON.toString());
50+
}
51+
4752
if (options?.EF !== undefined) {
4853
parser.push('EF', options.EF.toString());
4954
}

0 commit comments

Comments
 (0)