redis 6.3.0__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- redis/__init__.py +1 -2
- redis/_parsers/base.py +193 -8
- redis/_parsers/helpers.py +64 -6
- redis/_parsers/hiredis.py +16 -10
- redis/_parsers/resp3.py +11 -5
- redis/asyncio/client.py +65 -8
- redis/asyncio/cluster.py +57 -14
- redis/asyncio/connection.py +62 -2
- redis/asyncio/http/__init__.py +0 -0
- redis/asyncio/http/http_client.py +265 -0
- redis/asyncio/multidb/__init__.py +0 -0
- redis/asyncio/multidb/client.py +530 -0
- redis/asyncio/multidb/command_executor.py +339 -0
- redis/asyncio/multidb/config.py +210 -0
- redis/asyncio/multidb/database.py +69 -0
- redis/asyncio/multidb/event.py +84 -0
- redis/asyncio/multidb/failover.py +125 -0
- redis/asyncio/multidb/failure_detector.py +38 -0
- redis/asyncio/multidb/healthcheck.py +285 -0
- redis/background.py +204 -0
- redis/cache.py +1 -0
- redis/client.py +99 -22
- redis/cluster.py +14 -3
- redis/commands/core.py +348 -313
- redis/commands/helpers.py +0 -20
- redis/commands/json/_util.py +4 -2
- redis/commands/json/commands.py +2 -2
- redis/commands/search/__init__.py +2 -2
- redis/commands/search/aggregation.py +28 -30
- redis/commands/search/commands.py +13 -13
- redis/commands/search/field.py +2 -2
- redis/commands/search/query.py +23 -23
- redis/commands/vectorset/__init__.py +1 -1
- redis/commands/vectorset/commands.py +50 -25
- redis/commands/vectorset/utils.py +40 -4
- redis/connection.py +1258 -90
- redis/data_structure.py +81 -0
- redis/event.py +88 -14
- redis/exceptions.py +8 -0
- redis/http/__init__.py +0 -0
- redis/http/http_client.py +425 -0
- redis/maint_notifications.py +810 -0
- redis/multidb/__init__.py +0 -0
- redis/multidb/circuit.py +144 -0
- redis/multidb/client.py +526 -0
- redis/multidb/command_executor.py +350 -0
- redis/multidb/config.py +207 -0
- redis/multidb/database.py +130 -0
- redis/multidb/event.py +89 -0
- redis/multidb/exception.py +17 -0
- redis/multidb/failover.py +125 -0
- redis/multidb/failure_detector.py +104 -0
- redis/multidb/healthcheck.py +282 -0
- redis/retry.py +14 -1
- redis/utils.py +34 -0
- {redis-6.3.0.dist-info → redis-7.0.0.dist-info}/METADATA +7 -4
- redis-7.0.0.dist-info/RECORD +105 -0
- redis-6.3.0.dist-info/RECORD +0 -78
- {redis-6.3.0.dist-info → redis-7.0.0.dist-info}/WHEEL +0 -0
- {redis-6.3.0.dist-info → redis-7.0.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
from enum import Enum
|
|
3
|
-
from typing import Awaitable, Dict, List, Optional, Union
|
|
3
|
+
from typing import Any, Awaitable, Dict, List, Optional, Union
|
|
4
4
|
|
|
5
5
|
from redis.client import NEVER_DECODE
|
|
6
6
|
from redis.commands.helpers import get_protocol_version
|
|
@@ -19,6 +19,15 @@ VSETATTR_CMD = "VSETATTR"
|
|
|
19
19
|
VGETATTR_CMD = "VGETATTR"
|
|
20
20
|
VRANDMEMBER_CMD = "VRANDMEMBER"
|
|
21
21
|
|
|
22
|
+
# Return type for vsim command
|
|
23
|
+
VSimResult = Optional[
|
|
24
|
+
List[
|
|
25
|
+
Union[
|
|
26
|
+
List[EncodableT], Dict[EncodableT, Number], Dict[EncodableT, Dict[str, Any]]
|
|
27
|
+
]
|
|
28
|
+
]
|
|
29
|
+
]
|
|
30
|
+
|
|
22
31
|
|
|
23
32
|
class QuantizationOptions(Enum):
|
|
24
33
|
"""Quantization options for the VADD command."""
|
|
@@ -33,6 +42,7 @@ class CallbacksOptions(Enum):
|
|
|
33
42
|
|
|
34
43
|
RAW = "RAW"
|
|
35
44
|
WITHSCORES = "WITHSCORES"
|
|
45
|
+
WITHATTRIBS = "WITHATTRIBS"
|
|
36
46
|
ALLOW_DECODING = "ALLOW_DECODING"
|
|
37
47
|
RESP3 = "RESP3"
|
|
38
48
|
|
|
@@ -77,7 +87,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
77
87
|
``numlinks`` sets the number of links to create for the vector.
|
|
78
88
|
If not provided, the default number of links is used.
|
|
79
89
|
|
|
80
|
-
For more information see https://redis.io/commands/vadd
|
|
90
|
+
For more information, see https://redis.io/commands/vadd.
|
|
81
91
|
"""
|
|
82
92
|
if not vector or not element:
|
|
83
93
|
raise DataError("Both vector and element must be provided")
|
|
@@ -123,36 +133,40 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
123
133
|
key: KeyT,
|
|
124
134
|
input: Union[List[float], bytes, str],
|
|
125
135
|
with_scores: Optional[bool] = False,
|
|
136
|
+
with_attribs: Optional[bool] = False,
|
|
126
137
|
count: Optional[int] = None,
|
|
127
138
|
ef: Optional[Number] = None,
|
|
128
139
|
filter: Optional[str] = None,
|
|
129
140
|
filter_ef: Optional[str] = None,
|
|
130
141
|
truth: Optional[bool] = False,
|
|
131
142
|
no_thread: Optional[bool] = False,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
Optional[List[Union[List[EncodableT], Dict[EncodableT, Number]]]],
|
|
135
|
-
]:
|
|
143
|
+
epsilon: Optional[Number] = None,
|
|
144
|
+
) -> Union[Awaitable[VSimResult], VSimResult]:
|
|
136
145
|
"""
|
|
137
146
|
Compare a vector or element ``input`` with the other vectors in a vector set ``key``.
|
|
138
147
|
|
|
139
|
-
``with_scores`` sets if
|
|
140
|
-
|
|
148
|
+
``with_scores`` sets if similarity scores should be returned for each element in the result.
|
|
149
|
+
|
|
150
|
+
``with_attribs`` ``with_attribs`` sets if the results should be returned with the
|
|
151
|
+
attributes of the elements in the result, or None when no attributes are present.
|
|
141
152
|
|
|
142
153
|
``count`` sets the number of results to return.
|
|
143
154
|
|
|
144
155
|
``ef`` sets the exploration factor.
|
|
145
156
|
|
|
146
|
-
``filter`` sets filter that should be applied for the search.
|
|
157
|
+
``filter`` sets the filter that should be applied for the search.
|
|
147
158
|
|
|
148
159
|
``filter_ef`` sets the max filtering effort.
|
|
149
160
|
|
|
150
|
-
``truth`` when enabled forces the command to perform linear scan.
|
|
161
|
+
``truth`` when enabled, forces the command to perform a linear scan.
|
|
151
162
|
|
|
152
163
|
``no_thread`` when enabled forces the command to execute the search
|
|
153
164
|
on the data structure in the main thread.
|
|
154
165
|
|
|
155
|
-
|
|
166
|
+
``epsilon`` floating point between 0 and 1, if specified will return
|
|
167
|
+
only elements with distance no further than the specified one.
|
|
168
|
+
|
|
169
|
+
For more information, see https://redis.io/commands/vsim.
|
|
156
170
|
"""
|
|
157
171
|
|
|
158
172
|
if not input:
|
|
@@ -169,13 +183,24 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
169
183
|
else:
|
|
170
184
|
pieces.extend(["ELE", input])
|
|
171
185
|
|
|
172
|
-
if with_scores:
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
if with_scores or with_attribs:
|
|
187
|
+
if get_protocol_version(self.client) in ["3", 3]:
|
|
188
|
+
options[CallbacksOptions.RESP3.value] = True
|
|
189
|
+
|
|
190
|
+
if with_scores:
|
|
191
|
+
pieces.append("WITHSCORES")
|
|
192
|
+
options[CallbacksOptions.WITHSCORES.value] = True
|
|
193
|
+
|
|
194
|
+
if with_attribs:
|
|
195
|
+
pieces.append("WITHATTRIBS")
|
|
196
|
+
options[CallbacksOptions.WITHATTRIBS.value] = True
|
|
175
197
|
|
|
176
198
|
if count:
|
|
177
199
|
pieces.extend(["COUNT", count])
|
|
178
200
|
|
|
201
|
+
if epsilon:
|
|
202
|
+
pieces.extend(["EPSILON", epsilon])
|
|
203
|
+
|
|
179
204
|
if ef:
|
|
180
205
|
pieces.extend(["EF", ef])
|
|
181
206
|
|
|
@@ -203,7 +228,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
203
228
|
|
|
204
229
|
Raises `redis.exceptions.ResponseError` if the vector set doesn't exist.
|
|
205
230
|
|
|
206
|
-
For more information see https://redis.io/commands/vdim
|
|
231
|
+
For more information, see https://redis.io/commands/vdim.
|
|
207
232
|
"""
|
|
208
233
|
return self.execute_command(VDIM_CMD, key)
|
|
209
234
|
|
|
@@ -213,7 +238,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
213
238
|
|
|
214
239
|
Raises `redis.exceptions.ResponseError` if the vector set doesn't exist.
|
|
215
240
|
|
|
216
|
-
For more information see https://redis.io/commands/vcard
|
|
241
|
+
For more information, see https://redis.io/commands/vcard.
|
|
217
242
|
"""
|
|
218
243
|
return self.execute_command(VCARD_CMD, key)
|
|
219
244
|
|
|
@@ -221,7 +246,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
221
246
|
"""
|
|
222
247
|
Remove an element from a vector set.
|
|
223
248
|
|
|
224
|
-
For more information see https://redis.io/commands/vrem
|
|
249
|
+
For more information, see https://redis.io/commands/vrem.
|
|
225
250
|
"""
|
|
226
251
|
return self.execute_command(VREM_CMD, key, element)
|
|
227
252
|
|
|
@@ -235,10 +260,10 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
235
260
|
Get the approximated vector of an element ``element`` from vector set ``key``.
|
|
236
261
|
|
|
237
262
|
``raw`` is a boolean flag that indicates whether to return the
|
|
238
|
-
|
|
263
|
+
internal representation used by the vector.
|
|
239
264
|
|
|
240
265
|
|
|
241
|
-
For more information see https://redis.io/commands/
|
|
266
|
+
For more information, see https://redis.io/commands/vemb.
|
|
242
267
|
"""
|
|
243
268
|
options = {}
|
|
244
269
|
pieces = []
|
|
@@ -286,7 +311,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
286
311
|
If the ``WITHSCORES`` option is provided, the result is a list of dicts,
|
|
287
312
|
where each dict contains the neighbors for one level, with the scores as values.
|
|
288
313
|
|
|
289
|
-
For more information see https://redis.io/commands/vlinks
|
|
314
|
+
For more information, see https://redis.io/commands/vlinks
|
|
290
315
|
"""
|
|
291
316
|
options = {}
|
|
292
317
|
pieces = []
|
|
@@ -302,7 +327,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
302
327
|
"""
|
|
303
328
|
Get information about a vector set.
|
|
304
329
|
|
|
305
|
-
For more information see https://redis.io/commands/vinfo
|
|
330
|
+
For more information, see https://redis.io/commands/vinfo.
|
|
306
331
|
"""
|
|
307
332
|
return self.execute_command(VINFO_CMD, key)
|
|
308
333
|
|
|
@@ -313,7 +338,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
313
338
|
Associate or remove JSON attributes ``attributes`` of element ``element``
|
|
314
339
|
for vector set ``key``.
|
|
315
340
|
|
|
316
|
-
For more information see https://redis.io/commands/vsetattr
|
|
341
|
+
For more information, see https://redis.io/commands/vsetattr
|
|
317
342
|
"""
|
|
318
343
|
if attributes is None:
|
|
319
344
|
attributes_json = "{}"
|
|
@@ -329,12 +354,12 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
329
354
|
self, key: KeyT, element: str
|
|
330
355
|
) -> Union[Optional[Awaitable[dict]], Optional[dict]]:
|
|
331
356
|
"""
|
|
332
|
-
Retrieve the JSON attributes of an element ``
|
|
357
|
+
Retrieve the JSON attributes of an element ``element `` for vector set ``key``.
|
|
333
358
|
|
|
334
359
|
If the element does not exist, or if the vector set does not exist, None is
|
|
335
360
|
returned.
|
|
336
361
|
|
|
337
|
-
For more information see https://redis.io/commands/vgetattr
|
|
362
|
+
For more information, see https://redis.io/commands/vgetattr.
|
|
338
363
|
"""
|
|
339
364
|
return self.execute_command(VGETATTR_CMD, key, element)
|
|
340
365
|
|
|
@@ -358,7 +383,7 @@ class VectorSetCommands(CommandsProtocol):
|
|
|
358
383
|
|
|
359
384
|
If the vector set does not exist, ``None`` is returned.
|
|
360
385
|
|
|
361
|
-
For more information see https://redis.io/commands/vrandmember
|
|
386
|
+
For more information, see https://redis.io/commands/vrandmember.
|
|
362
387
|
"""
|
|
363
388
|
pieces = []
|
|
364
389
|
pieces.append(key)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
1
3
|
from redis._parsers.helpers import pairs_to_dict
|
|
2
4
|
from redis.commands.vectorset.commands import CallbacksOptions
|
|
3
5
|
|
|
@@ -75,19 +77,53 @@ def parse_vsim_result(response, **options):
|
|
|
75
77
|
structures depending on input options.
|
|
76
78
|
Parsing VSIM result into:
|
|
77
79
|
- List[List[str]]
|
|
78
|
-
- List[Dict[str, Number]]
|
|
80
|
+
- List[Dict[str, Number]] - when with_scores is used (without attributes)
|
|
81
|
+
- List[Dict[str, Mapping[str, Any]]] - when with_attribs is used (without scores)
|
|
82
|
+
- List[Dict[str, Union[Number, Mapping[str, Any]]]] - when with_scores and with_attribs are used
|
|
83
|
+
|
|
79
84
|
"""
|
|
80
85
|
if response is None:
|
|
81
86
|
return response
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
withscores = bool(options.get(CallbacksOptions.WITHSCORES.value))
|
|
89
|
+
withattribs = bool(options.get(CallbacksOptions.WITHATTRIBS.value))
|
|
90
|
+
|
|
91
|
+
# Exactly one of withscores or withattribs is True
|
|
92
|
+
if (withscores and not withattribs) or (not withscores and withattribs):
|
|
84
93
|
# Redis will return a list of list of pairs.
|
|
85
94
|
# This list have to be transformed to dict
|
|
86
95
|
result_dict = {}
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
if options.get(CallbacksOptions.RESP3.value):
|
|
97
|
+
resp_dict = response
|
|
98
|
+
else:
|
|
99
|
+
resp_dict = pairs_to_dict(response)
|
|
100
|
+
for key, value in resp_dict.items():
|
|
101
|
+
if withscores:
|
|
102
|
+
value = float(value)
|
|
103
|
+
else:
|
|
104
|
+
value = json.loads(value) if value else None
|
|
105
|
+
|
|
89
106
|
result_dict[key] = value
|
|
90
107
|
return result_dict
|
|
108
|
+
elif withscores and withattribs:
|
|
109
|
+
it = iter(response)
|
|
110
|
+
result_dict = {}
|
|
111
|
+
if options.get(CallbacksOptions.RESP3.value):
|
|
112
|
+
for elem, data in response.items():
|
|
113
|
+
if data[1] is not None:
|
|
114
|
+
attribs_dict = json.loads(data[1])
|
|
115
|
+
else:
|
|
116
|
+
attribs_dict = None
|
|
117
|
+
result_dict[elem] = {"score": data[0], "attributes": attribs_dict}
|
|
118
|
+
else:
|
|
119
|
+
for elem, score, attribs in zip(it, it, it):
|
|
120
|
+
if attribs is not None:
|
|
121
|
+
attribs_dict = json.loads(attribs)
|
|
122
|
+
else:
|
|
123
|
+
attribs_dict = None
|
|
124
|
+
|
|
125
|
+
result_dict[elem] = {"score": float(score), "attributes": attribs_dict}
|
|
126
|
+
return result_dict
|
|
91
127
|
else:
|
|
92
128
|
# return the list of elements for each level
|
|
93
129
|
# list of lists
|