Skip to content

Commit 3cfd60f

Browse files
committed
properly transform vinfo result
1 parent d60338d commit 3cfd60f

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,41 @@ describe('VINFO', () => {
1515
await client.vAdd('key', [1.0, 2.0, 3.0], 'element');
1616

1717
const result = await client.vInfo('key');
18-
assert.ok(Array.isArray(result));
18+
assert.ok(typeof result === 'object' && result !== null);
19+
20+
assert.equal(result['vector-dim'], 3);
21+
assert.equal(result['size'], 1);
22+
assert.ok('quant-type' in result);
23+
assert.ok('hnsw-m' in result);
24+
assert.ok('projection-input-dim' in result);
25+
assert.ok('max-level' in result);
26+
assert.ok('attributes-count' in result);
27+
assert.ok('vset-uid' in result);
28+
assert.ok('hnsw-max-node-uid' in result);
1929
}, {
2030
client: GLOBAL.SERVERS.OPEN,
2131
cluster: GLOBAL.CLUSTERS.OPEN
2232
});
33+
34+
testUtils.testWithClient('vInfo with RESP3', async client => {
35+
await client.vAdd('resp3-key', [1.0, 2.0, 3.0], 'resp3-element');
36+
37+
const result = await client.vInfo('resp3-key');
38+
assert.ok(typeof result === 'object' && result !== null);
39+
40+
assert.equal(result['vector-dim'], 3);
41+
assert.equal(result['size'], 1);
42+
assert.ok('quant-type' in result);
43+
assert.ok('hnsw-m' in result);
44+
assert.ok('projection-input-dim' in result);
45+
assert.ok('max-level' in result);
46+
assert.ok('attributes-count' in result);
47+
assert.ok('vset-uid' in result);
48+
assert.ok('hnsw-max-node-uid' in result);
49+
}, {
50+
...GLOBAL.SERVERS.OPEN,
51+
clientOptions: {
52+
RESP: 3
53+
}
54+
});
2355
});

packages/client/lib/commands/VINFO.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { CommandParser } from '../client/parser';
2-
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
2+
import { RedisArgument, Command, UnwrapReply, Resp2Reply, TuplesToMapReply, SimpleStringReply, NumberReply } from '../RESP/types';
3+
4+
export type VInfoReplyMap = TuplesToMapReply<[
5+
[SimpleStringReply<'quant-type'>, SimpleStringReply],
6+
[SimpleStringReply<'vector-dim'>, NumberReply],
7+
[SimpleStringReply<'size'>, NumberReply],
8+
[SimpleStringReply<'max-level'>, NumberReply],
9+
[SimpleStringReply<'vset-uid'>, NumberReply],
10+
[SimpleStringReply<'hnsw-max-node-uid'>, NumberReply],
11+
]>;
312

413
export default {
514
IS_READ_ONLY: true,
@@ -14,5 +23,16 @@ export default {
1423
parser.push('VINFO');
1524
parser.pushKey(key);
1625
},
17-
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
26+
transformReply: {
27+
2: (reply: UnwrapReply<Resp2Reply<VInfoReplyMap>>): VInfoReplyMap => {
28+
const ret = Object.create(null);
29+
30+
for (let i = 0; i < reply.length; i += 2) {
31+
ret[reply[i].toString()] = reply[i + 1];
32+
}
33+
34+
return ret as unknown as VInfoReplyMap;
35+
},
36+
3: undefined as unknown as () => VInfoReplyMap
37+
}
1838
} as const satisfies Command;

0 commit comments

Comments
 (0)