Skip to content

Commit fd2d427

Browse files
committed
Adding VectorSet commands support. (#3584)
1 parent a9155f4 commit fd2d427

File tree

7 files changed

+2231
-2
lines changed

7 files changed

+2231
-2
lines changed

Diff for: docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
x-client-libs-stack-image: &client-libs-stack-image
3-
image: "redislabs/client-libs-test:${CLIENT_LIBS_TEST_STACK_IMAGE_TAG:-rs-7.4.0-v2}"
3+
image: "redislabs/client-libs-test:${CLIENT_LIBS_TEST_STACK_IMAGE_TAG:-8.0-M06-pre}"
44

55
x-client-libs-image: &client-libs-image
6-
image: "redislabs/client-libs-test:${CLIENT_LIBS_TEST_IMAGE_TAG:-7.4.2}"
6+
image: "redislabs/client-libs-test:${CLIENT_LIBS_TEST_IMAGE_TAG:-8.0-M06-pre}"
77

88
services:
99

Diff for: redis/commands/redismodules.py

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def tdigest(self):
7272
tdigest = TDigestBloom(client=self)
7373
return tdigest
7474

75+
def vset(self):
76+
"""Access the VectorSet commands namespace."""
77+
78+
from .vectorset import VectorSet
79+
80+
vset = VectorSet(client=self)
81+
return vset
82+
7583

7684
class AsyncRedisModuleCommands(RedisModuleCommands):
7785
def ft(self, index_name="idx"):

Diff for: redis/commands/vectorset/__init__.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
3+
from redis._parsers.helpers import pairs_to_dict
4+
from redis.commands.vectorset.utils import (
5+
parse_vemb_result,
6+
parse_vlinks_result,
7+
parse_vsim_result,
8+
)
9+
10+
from ..helpers import get_protocol_version
11+
from .commands import (
12+
VEMB_CMD,
13+
VGETATTR_CMD,
14+
VINFO_CMD,
15+
VLINKS_CMD,
16+
VSIM_CMD,
17+
VectorSetCommands,
18+
)
19+
20+
21+
class VectorSet(VectorSetCommands):
22+
def __init__(self, client, **kwargs):
23+
"""Create a new VectorSet client."""
24+
# Set the module commands' callbacks
25+
self._MODULE_CALLBACKS = {
26+
VEMB_CMD: parse_vemb_result,
27+
VGETATTR_CMD: lambda r: r and json.loads(r) or None,
28+
}
29+
30+
self._RESP2_MODULE_CALLBACKS = {
31+
VINFO_CMD: lambda r: r and pairs_to_dict(r) or None,
32+
VSIM_CMD: parse_vsim_result,
33+
VLINKS_CMD: parse_vlinks_result,
34+
}
35+
self._RESP3_MODULE_CALLBACKS = {}
36+
37+
self.client = client
38+
self.execute_command = client.execute_command
39+
40+
if get_protocol_version(self.client) in ["3", 3]:
41+
self._MODULE_CALLBACKS.update(self._RESP3_MODULE_CALLBACKS)
42+
else:
43+
self._MODULE_CALLBACKS.update(self._RESP2_MODULE_CALLBACKS)
44+
45+
for k, v in self._MODULE_CALLBACKS.items():
46+
self.client.set_response_callback(k, v)

0 commit comments

Comments
 (0)