Skip to content

Commit 6483865

Browse files
committed
resp3 tests
1 parent f2ddb1d commit 6483865

File tree

6 files changed

+149
-3
lines changed

6 files changed

+149
-3
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('VADD', () => {
1414

1515
it('with REDUCE option', () => {
1616
assert.deepEqual(
17-
parseArgs(VADD, 'key', [1.0, 2.0], 'element', { REDUCE: 50 }),
17+
parseArgs(VADD, 'key', [1.0, 2], 'element', { REDUCE: 50 }),
1818
['VADD', 'key', 'REDUCE', '50', 'VALUES', '2', '1', '2', 'element']
1919
);
2020
});
@@ -63,4 +63,33 @@ describe('VADD', () => {
6363
client: GLOBAL.SERVERS.OPEN,
6464
cluster: GLOBAL.CLUSTERS.OPEN
6565
});
66+
67+
testUtils.testWithClient('vAdd with RESP3', async client => {
68+
// Test basic functionality with RESP3
69+
assert.equal(
70+
await client.vAdd('resp3-key', [1.5, 2.5, 3.5], 'resp3-element'),
71+
true
72+
);
73+
74+
// Test with options to ensure complex parameters work with RESP3
75+
assert.equal(
76+
await client.vAdd('resp3-key', [4.0, 5.0, 6.0], 'resp3-element2', {
77+
QUANT: 'Q8',
78+
CAS: true,
79+
SETATTR: { type: 'test', value: 123 }
80+
}),
81+
true
82+
);
83+
84+
// Verify the vector set was created correctly
85+
assert.equal(
86+
await client.vCard('resp3-key'),
87+
2
88+
);
89+
}, {
90+
...GLOBAL.SERVERS.OPEN,
91+
clientOptions: {
92+
RESP: 3
93+
}
94+
});
6695
});

packages/client/lib/commands/VADD.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommandParser } from '../client/parser';
2-
import { RedisArgument, NumberReply, Command } from '../RESP/types';
2+
import { RedisArgument, NumberReply, Command, BooleanReply } from '../RESP/types';
33
import { transformDoubleArgument } from './generic-transformers';
44

55
export interface VAddOptions {
@@ -61,5 +61,8 @@ export default {
6161
parser.push('M', options.M.toString());
6262
}
6363
},
64-
transformReply: undefined as unknown as () => NumberReply
64+
transformReply: {
65+
2: undefined as unknown as () => NumberReply,
66+
3: undefined as unknown as () => BooleanReply
67+
}
6568
} as const satisfies Command;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,31 @@ describe('VCARD', () => {
2323
client: GLOBAL.SERVERS.OPEN,
2424
cluster: GLOBAL.CLUSTERS.OPEN
2525
});
26+
27+
testUtils.testWithClient('vCard with RESP3', async client => {
28+
// Test empty vector set
29+
assert.equal(
30+
await client.vCard('resp3-empty-key'),
31+
0
32+
);
33+
34+
// Add elements and test cardinality
35+
await client.vAdd('resp3-key', [1.0, 2.0], 'elem1');
36+
assert.equal(
37+
await client.vCard('resp3-key'),
38+
1
39+
);
40+
41+
await client.vAdd('resp3-key', [3.0, 4.0], 'elem2');
42+
await client.vAdd('resp3-key', [5.0, 6.0], 'elem3');
43+
assert.equal(
44+
await client.vCard('resp3-key'),
45+
3
46+
);
47+
}, {
48+
...GLOBAL.SERVERS.OPEN,
49+
clientOptions: {
50+
RESP: 3
51+
}
52+
});
2653
});

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,31 @@ describe('VDIM', () => {
2222
client: GLOBAL.SERVERS.OPEN,
2323
cluster: GLOBAL.CLUSTERS.OPEN
2424
});
25+
26+
testUtils.testWithClient('vDim with RESP3', async client => {
27+
// Test with different vector dimensions
28+
await client.vAdd('resp3-2d', [1.0, 2.0], 'elem2d');
29+
assert.equal(
30+
await client.vDim('resp3-2d'),
31+
2
32+
);
33+
34+
await client.vAdd('resp3-5d', [1.0, 2.0, 3.0, 4.0, 5.0], 'elem5d');
35+
assert.equal(
36+
await client.vDim('resp3-5d'),
37+
5
38+
);
39+
40+
// Verify dimension consistency within the same vector set
41+
await client.vAdd('resp3-5d', [6.0, 7.0, 8.0, 9.0, 10.0], 'elem5d-2');
42+
assert.equal(
43+
await client.vDim('resp3-5d'),
44+
5
45+
);
46+
}, {
47+
...GLOBAL.SERVERS.OPEN,
48+
clientOptions: {
49+
RESP: 3
50+
}
51+
});
2552
});

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,30 @@ describe('VEMB', () => {
2121
client: GLOBAL.SERVERS.OPEN,
2222
cluster: GLOBAL.CLUSTERS.OPEN
2323
});
24+
25+
testUtils.testWithClient('vEmb with RESP3', async client => {
26+
// Test retrieving embeddings with RESP3
27+
const originalVector = [1.5, 2.5, 3.5, 4.5];
28+
await client.vAdd('resp3-key', originalVector, 'resp3-element');
29+
30+
const embedding = await client.vEmb('resp3-key', 'resp3-element');
31+
assert.ok(Array.isArray(embedding));
32+
assert.equal(embedding.length, 4);
33+
34+
// Verify that all values are numbers (RESP3 should preserve numeric types)
35+
embedding.forEach(value => {
36+
assert.equal(typeof value, 'number');
37+
});
38+
39+
// Test with quantized vector to ensure RESP3 handles different precision
40+
await client.vAdd('resp3-key', [10.0, 20.0, 30.0, 40.0], 'quantized-elem', { QUANT: 'Q8' });
41+
const quantizedEmbedding = await client.vEmb('resp3-key', 'quantized-elem');
42+
assert.ok(Array.isArray(quantizedEmbedding));
43+
assert.equal(quantizedEmbedding.length, 4);
44+
}, {
45+
...GLOBAL.SERVERS.OPEN,
46+
clientOptions: {
47+
RESP: 3
48+
}
49+
});
2450
});

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,38 @@ describe('VGETATTR', () => {
2121
client: GLOBAL.SERVERS.OPEN,
2222
cluster: GLOBAL.CLUSTERS.OPEN
2323
});
24+
25+
testUtils.testWithClient('vGetAttr with RESP3', async client => {
26+
// Test getting attributes with RESP3
27+
await client.vAdd('resp3-key', [1.0, 2.0], 'resp3-element');
28+
29+
// Test null case (no attributes set)
30+
const nullResult = await client.vGetAttr('resp3-key', 'resp3-element');
31+
assert.equal(nullResult, null);
32+
33+
// Set complex attributes and retrieve them
34+
const complexAttrs = {
35+
name: 'test-item',
36+
category: 'electronics',
37+
price: 99.99,
38+
inStock: true,
39+
tags: ['new', 'featured']
40+
};
41+
await client.vSetAttr('resp3-key', 'resp3-element', complexAttrs);
42+
43+
const result = await client.vGetAttr('resp3-key', 'resp3-element');
44+
assert.ok(result !== null);
45+
46+
// Parse the JSON result and verify structure
47+
const parsedAttrs = JSON.parse(result.toString());
48+
assert.equal(parsedAttrs.name, 'test-item');
49+
assert.equal(parsedAttrs.price, 99.99);
50+
assert.equal(parsedAttrs.inStock, true);
51+
assert.ok(Array.isArray(parsedAttrs.tags));
52+
}, {
53+
...GLOBAL.SERVERS.OPEN,
54+
clientOptions: {
55+
RESP: 3
56+
}
57+
});
2458
});

0 commit comments

Comments
 (0)