coredis 4.24.0__py3-none-any.whl → 5.0.0rc1__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.
Potentially problematic release.
This version of coredis might be problematic. Click here for more details.
- coredis/__init__.py +1 -3
- coredis/_packer.py +10 -10
- coredis/_protocols.py +23 -32
- coredis/_py_311_typing.py +20 -0
- coredis/_py_312_typing.py +17 -0
- coredis/_utils.py +49 -51
- coredis/_version.py +3 -3
- coredis/cache.py +57 -82
- coredis/client/__init__.py +1 -2
- coredis/client/basic.py +129 -56
- coredis/client/cluster.py +147 -70
- coredis/commands/__init__.py +27 -7
- coredis/commands/_key_spec.py +11 -10
- coredis/commands/_utils.py +1 -1
- coredis/commands/_validators.py +30 -20
- coredis/commands/_wrappers.py +19 -99
- coredis/commands/bitfield.py +10 -2
- coredis/commands/constants.py +20 -3
- coredis/commands/core.py +1627 -1246
- coredis/commands/function.py +21 -19
- coredis/commands/monitor.py +0 -71
- coredis/commands/pubsub.py +7 -142
- coredis/commands/request.py +108 -0
- coredis/commands/script.py +9 -9
- coredis/commands/sentinel.py +60 -49
- coredis/connection.py +14 -15
- coredis/exceptions.py +2 -2
- coredis/experimental/__init__.py +0 -4
- coredis/globals.py +3 -0
- coredis/modules/autocomplete.py +28 -30
- coredis/modules/base.py +15 -31
- coredis/modules/filters.py +269 -245
- coredis/modules/graph.py +61 -62
- coredis/modules/json.py +172 -140
- coredis/modules/response/_callbacks/autocomplete.py +5 -4
- coredis/modules/response/_callbacks/graph.py +34 -29
- coredis/modules/response/_callbacks/json.py +5 -3
- coredis/modules/response/_callbacks/search.py +49 -53
- coredis/modules/response/_callbacks/timeseries.py +18 -30
- coredis/modules/response/types.py +1 -5
- coredis/modules/search.py +186 -169
- coredis/modules/timeseries.py +184 -164
- coredis/parser.py +6 -19
- coredis/pipeline.py +391 -422
- coredis/pool/basic.py +7 -7
- coredis/pool/cluster.py +3 -3
- coredis/pool/nodemanager.py +10 -3
- coredis/response/_callbacks/__init__.py +76 -57
- coredis/response/_callbacks/acl.py +0 -3
- coredis/response/_callbacks/cluster.py +25 -16
- coredis/response/_callbacks/command.py +8 -6
- coredis/response/_callbacks/connection.py +4 -3
- coredis/response/_callbacks/geo.py +17 -13
- coredis/response/_callbacks/hash.py +13 -11
- coredis/response/_callbacks/keys.py +9 -5
- coredis/response/_callbacks/module.py +2 -3
- coredis/response/_callbacks/script.py +6 -8
- coredis/response/_callbacks/sentinel.py +21 -17
- coredis/response/_callbacks/server.py +36 -14
- coredis/response/_callbacks/sets.py +3 -4
- coredis/response/_callbacks/sorted_set.py +27 -24
- coredis/response/_callbacks/streams.py +22 -13
- coredis/response/_callbacks/strings.py +7 -6
- coredis/response/_callbacks/vector_sets.py +126 -0
- coredis/response/types.py +13 -4
- coredis/sentinel.py +1 -1
- coredis/stream.py +4 -3
- coredis/tokens.py +343 -16
- coredis/typing.py +432 -79
- {coredis-4.24.0.dist-info → coredis-5.0.0rc1.dist-info}/METADATA +4 -5
- coredis-5.0.0rc1.dist-info/RECORD +95 -0
- coredis/client/keydb.py +0 -336
- coredis/pipeline.pyi +0 -2103
- coredis-4.24.0.dist-info/RECORD +0 -93
- {coredis-4.24.0.dist-info → coredis-5.0.0rc1.dist-info}/WHEEL +0 -0
- {coredis-4.24.0.dist-info → coredis-5.0.0rc1.dist-info}/licenses/LICENSE +0 -0
- {coredis-4.24.0.dist-info → coredis-5.0.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -9,7 +9,6 @@ from coredis.typing import (
|
|
|
9
9
|
Generic,
|
|
10
10
|
ResponsePrimitive,
|
|
11
11
|
ResponseType,
|
|
12
|
-
ValueT,
|
|
13
12
|
)
|
|
14
13
|
|
|
15
14
|
|
|
@@ -23,9 +22,8 @@ class ZRankCallback(
|
|
|
23
22
|
def transform(
|
|
24
23
|
self,
|
|
25
24
|
response: int | list[ResponsePrimitive] | None,
|
|
26
|
-
**options: ValueT | None,
|
|
27
25
|
) -> int | tuple[int, float] | None:
|
|
28
|
-
if options.get("withscore"):
|
|
26
|
+
if self.options.get("withscore"):
|
|
29
27
|
return (response[0], float(response[1])) if response else None
|
|
30
28
|
else:
|
|
31
29
|
return cast(int | None, response)
|
|
@@ -33,9 +31,8 @@ class ZRankCallback(
|
|
|
33
31
|
def transform_3(
|
|
34
32
|
self,
|
|
35
33
|
response: int | list[ResponsePrimitive] | None,
|
|
36
|
-
**options: ValueT | None,
|
|
37
34
|
) -> int | tuple[int, float] | None:
|
|
38
|
-
if options.get("withscore"):
|
|
35
|
+
if self.options.get("withscore"):
|
|
39
36
|
return (response[0], response[1]) if response else None
|
|
40
37
|
else:
|
|
41
38
|
return cast(int | None, response)
|
|
@@ -51,11 +48,10 @@ class ZMembersOrScoredMembers(
|
|
|
51
48
|
def transform(
|
|
52
49
|
self,
|
|
53
50
|
response: list[AnyStr | list[ResponsePrimitive]],
|
|
54
|
-
**options: ValueT | None,
|
|
55
51
|
) -> tuple[AnyStr | ScoredMember, ...]:
|
|
56
52
|
if not response:
|
|
57
53
|
return ()
|
|
58
|
-
elif options.get("withscores"):
|
|
54
|
+
elif self.options.get("withscores"):
|
|
59
55
|
it = iter(cast(list[AnyStr], response))
|
|
60
56
|
return tuple(ScoredMember(*v) for v in zip(it, map(float, it)))
|
|
61
57
|
else:
|
|
@@ -64,9 +60,8 @@ class ZMembersOrScoredMembers(
|
|
|
64
60
|
def transform_3(
|
|
65
61
|
self,
|
|
66
62
|
response: list[AnyStr | list[ResponsePrimitive]],
|
|
67
|
-
**options: ValueT | None,
|
|
68
63
|
) -> tuple[AnyStr | ScoredMember, ...]:
|
|
69
|
-
if options.get("withscores"):
|
|
64
|
+
if self.options.get("withscores"):
|
|
70
65
|
return tuple(ScoredMember(*v) for v in cast(list[tuple[AnyStr, float]], response))
|
|
71
66
|
else:
|
|
72
67
|
return cast(tuple[AnyStr, ...], tuple(response))
|
|
@@ -81,12 +76,13 @@ class ZSetScorePairCallback(
|
|
|
81
76
|
Generic[AnyStr],
|
|
82
77
|
):
|
|
83
78
|
def transform(
|
|
84
|
-
self,
|
|
79
|
+
self,
|
|
80
|
+
response: list[ResponsePrimitive] | None,
|
|
85
81
|
) -> ScoredMember | ScoredMembers | None:
|
|
86
82
|
if not response:
|
|
87
83
|
return None
|
|
88
84
|
|
|
89
|
-
if not (options.get("withscores") or options.get("count")):
|
|
85
|
+
if not (self.options.get("withscores") or self.options.get("count")):
|
|
90
86
|
return ScoredMember(cast(AnyStr, response[0]), float(cast(SupportsFloat, response[1])))
|
|
91
87
|
|
|
92
88
|
it = iter(response)
|
|
@@ -95,12 +91,11 @@ class ZSetScorePairCallback(
|
|
|
95
91
|
def transform_3(
|
|
96
92
|
self,
|
|
97
93
|
response: list[ResponsePrimitive | list[ResponsePrimitive]] | None,
|
|
98
|
-
**options: ValueT | None,
|
|
99
94
|
) -> ScoredMember | ScoredMembers | None:
|
|
100
95
|
if not response:
|
|
101
96
|
return None
|
|
102
97
|
|
|
103
|
-
if not (options.get("withscores") or options.get("count")):
|
|
98
|
+
if not (self.options.get("withscores") or self.options.get("count")):
|
|
104
99
|
return ScoredMember(*cast(tuple[AnyStr, float], response))
|
|
105
100
|
|
|
106
101
|
return tuple(ScoredMember(*v) for v in cast(list[tuple[AnyStr, float]], response))
|
|
@@ -115,7 +110,8 @@ class ZMPopCallback(
|
|
|
115
110
|
Generic[AnyStr],
|
|
116
111
|
):
|
|
117
112
|
def transform(
|
|
118
|
-
self,
|
|
113
|
+
self,
|
|
114
|
+
response: list[ResponseType] | None,
|
|
119
115
|
) -> tuple[AnyStr, ScoredMembers] | None:
|
|
120
116
|
r = cast(tuple[AnyStr, list[tuple[AnyStr, int]]], response)
|
|
121
117
|
if r:
|
|
@@ -128,7 +124,8 @@ class ZMScoreCallback(
|
|
|
128
124
|
ResponseCallback[list[ResponsePrimitive], list[ResponsePrimitive], tuple[float | None, ...]]
|
|
129
125
|
):
|
|
130
126
|
def transform(
|
|
131
|
-
self,
|
|
127
|
+
self,
|
|
128
|
+
response: list[ResponsePrimitive],
|
|
132
129
|
) -> tuple[float | None, ...]:
|
|
133
130
|
return tuple(score if score is None else float(score) for score in response)
|
|
134
131
|
|
|
@@ -138,7 +135,8 @@ class ZScanCallback(
|
|
|
138
135
|
Generic[AnyStr],
|
|
139
136
|
):
|
|
140
137
|
def transform(
|
|
141
|
-
self,
|
|
138
|
+
self,
|
|
139
|
+
response: list[ResponseType],
|
|
142
140
|
) -> tuple[int, ScoredMembers]:
|
|
143
141
|
cursor, r = cast(tuple[int, list[AnyStr]], response)
|
|
144
142
|
it = iter(r)
|
|
@@ -157,9 +155,8 @@ class ZRandMemberCallback(
|
|
|
157
155
|
def transform(
|
|
158
156
|
self,
|
|
159
157
|
response: AnyStr | list[ResponsePrimitive] | None,
|
|
160
|
-
**options: ValueT | None,
|
|
161
158
|
) -> AnyStr | tuple[AnyStr, ...] | ScoredMembers | None:
|
|
162
|
-
if not (response and options.get("withscores")):
|
|
159
|
+
if not (response and self.options.get("withscores")):
|
|
163
160
|
return tuple(response) if isinstance(response, list) else response
|
|
164
161
|
|
|
165
162
|
it = iter(response)
|
|
@@ -168,9 +165,8 @@ class ZRandMemberCallback(
|
|
|
168
165
|
def transform_3(
|
|
169
166
|
self,
|
|
170
167
|
response: AnyStr | list[list[ResponsePrimitive]] | list[ResponsePrimitive] | None,
|
|
171
|
-
**options: ValueT | None,
|
|
172
168
|
) -> AnyStr | tuple[AnyStr, ...] | ScoredMembers | None:
|
|
173
|
-
if not (response and options.get("withscores")):
|
|
169
|
+
if not (response and self.options.get("withscores")):
|
|
174
170
|
return tuple(response) if isinstance(response, list) else response
|
|
175
171
|
|
|
176
172
|
return tuple(ScoredMember(*v) for v in response)
|
|
@@ -184,7 +180,8 @@ class BZPopCallback(
|
|
|
184
180
|
]
|
|
185
181
|
):
|
|
186
182
|
def transform(
|
|
187
|
-
self,
|
|
183
|
+
self,
|
|
184
|
+
response: list[ResponsePrimitive] | None,
|
|
188
185
|
) -> tuple[AnyStr, AnyStr, float] | None:
|
|
189
186
|
if response:
|
|
190
187
|
return response[0], response[1], float(response[2])
|
|
@@ -192,10 +189,16 @@ class BZPopCallback(
|
|
|
192
189
|
|
|
193
190
|
|
|
194
191
|
class ZAddCallback(ResponseCallback[ResponsePrimitive, int | float, int | float]):
|
|
195
|
-
def transform(
|
|
196
|
-
|
|
192
|
+
def transform(
|
|
193
|
+
self,
|
|
194
|
+
response: ResponsePrimitive,
|
|
195
|
+
) -> int | float:
|
|
196
|
+
if self.options.get("condition"):
|
|
197
197
|
return float(response)
|
|
198
198
|
return int(response)
|
|
199
199
|
|
|
200
|
-
def transform_3(
|
|
200
|
+
def transform_3(
|
|
201
|
+
self,
|
|
202
|
+
response: int | float,
|
|
203
|
+
) -> int | float:
|
|
201
204
|
return response
|
|
@@ -16,13 +16,13 @@ from coredis.typing import (
|
|
|
16
16
|
OrderedDict,
|
|
17
17
|
ResponseType,
|
|
18
18
|
StringT,
|
|
19
|
-
ValueT,
|
|
20
19
|
)
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class StreamRangeCallback(ResponseCallback[ResponseType, ResponseType, tuple[StreamEntry, ...]]):
|
|
24
23
|
def transform(
|
|
25
|
-
self,
|
|
24
|
+
self,
|
|
25
|
+
response: ResponseType,
|
|
26
26
|
) -> tuple[StreamEntry, ...]:
|
|
27
27
|
return tuple(StreamEntry(r[0], flat_pairs_to_ordered_dict(r[1])) for r in response)
|
|
28
28
|
|
|
@@ -31,9 +31,10 @@ class ClaimCallback(
|
|
|
31
31
|
ResponseCallback[ResponseType, ResponseType, tuple[AnyStr, ...] | tuple[StreamEntry, ...]]
|
|
32
32
|
):
|
|
33
33
|
def transform(
|
|
34
|
-
self,
|
|
34
|
+
self,
|
|
35
|
+
response: ResponseType,
|
|
35
36
|
) -> tuple[AnyStr, ...] | tuple[StreamEntry, ...]:
|
|
36
|
-
if options.get("justid") is not None:
|
|
37
|
+
if self.options.get("justid") is not None:
|
|
37
38
|
return tuple(response)
|
|
38
39
|
else:
|
|
39
40
|
return StreamRangeCallback()(response)
|
|
@@ -48,12 +49,13 @@ class AutoClaimCallback(
|
|
|
48
49
|
]
|
|
49
50
|
):
|
|
50
51
|
def transform(
|
|
51
|
-
self,
|
|
52
|
+
self,
|
|
53
|
+
response: ResponseType,
|
|
52
54
|
) -> (
|
|
53
55
|
tuple[AnyStr, tuple[AnyStr, ...]]
|
|
54
56
|
| tuple[AnyStr, tuple[StreamEntry, ...], tuple[AnyStr, ...]]
|
|
55
57
|
):
|
|
56
|
-
if options.get("justid") is not None:
|
|
58
|
+
if self.options.get("justid") is not None:
|
|
57
59
|
return response[0], tuple(response[1])
|
|
58
60
|
else:
|
|
59
61
|
return (
|
|
@@ -67,7 +69,8 @@ class MultiStreamRangeCallback(
|
|
|
67
69
|
ResponseCallback[ResponseType, ResponseType, dict[AnyStr, tuple[StreamEntry, ...]] | None]
|
|
68
70
|
):
|
|
69
71
|
def transform_3(
|
|
70
|
-
self,
|
|
72
|
+
self,
|
|
73
|
+
response: ResponseType,
|
|
71
74
|
) -> dict[AnyStr, tuple[StreamEntry, ...]] | None:
|
|
72
75
|
if response:
|
|
73
76
|
mapping: dict[AnyStr, tuple[StreamEntry, ...]] = {}
|
|
@@ -81,7 +84,8 @@ class MultiStreamRangeCallback(
|
|
|
81
84
|
return None
|
|
82
85
|
|
|
83
86
|
def transform(
|
|
84
|
-
self,
|
|
87
|
+
self,
|
|
88
|
+
response: ResponseType,
|
|
85
89
|
) -> dict[AnyStr, tuple[StreamEntry, ...]] | None:
|
|
86
90
|
if response:
|
|
87
91
|
mapping: dict[AnyStr, tuple[StreamEntry, ...]] = {}
|
|
@@ -99,9 +103,10 @@ class PendingCallback(
|
|
|
99
103
|
ResponseCallback[ResponseType, ResponseType, StreamPending | tuple[StreamPendingExt, ...]]
|
|
100
104
|
):
|
|
101
105
|
def transform(
|
|
102
|
-
self,
|
|
106
|
+
self,
|
|
107
|
+
response: ResponseType,
|
|
103
108
|
) -> StreamPending | tuple[StreamPendingExt, ...]:
|
|
104
|
-
if not options.get("count"):
|
|
109
|
+
if not self.options.get("count"):
|
|
105
110
|
return StreamPending(
|
|
106
111
|
response[0],
|
|
107
112
|
response[1],
|
|
@@ -114,15 +119,19 @@ class PendingCallback(
|
|
|
114
119
|
|
|
115
120
|
class XInfoCallback(ResponseCallback[ResponseType, ResponseType, tuple[dict[AnyStr, AnyStr], ...]]):
|
|
116
121
|
def transform(
|
|
117
|
-
self,
|
|
122
|
+
self,
|
|
123
|
+
response: ResponseType,
|
|
118
124
|
) -> tuple[dict[AnyStr, AnyStr], ...]:
|
|
119
125
|
return tuple(flat_pairs_to_dict(row) for row in response)
|
|
120
126
|
|
|
121
127
|
|
|
122
128
|
class StreamInfoCallback(ResponseCallback[ResponseType, ResponseType, StreamInfo]):
|
|
123
|
-
def transform(
|
|
129
|
+
def transform(
|
|
130
|
+
self,
|
|
131
|
+
response: ResponseType,
|
|
132
|
+
) -> StreamInfo:
|
|
124
133
|
res: dict[StringT, Any] = EncodingInsensitiveDict(flat_pairs_to_dict(response))
|
|
125
|
-
if not options.get("full"):
|
|
134
|
+
if not self.options.get("full"):
|
|
126
135
|
k1 = "first-entry"
|
|
127
136
|
kn = "last-entry"
|
|
128
137
|
e1: StreamEntry | None = None
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
3
5
|
from coredis._utils import EncodingInsensitiveDict
|
|
4
6
|
from coredis.response._callbacks import ResponseCallback, SimpleStringCallback
|
|
5
7
|
from coredis.response.types import LCSMatch, LCSResult
|
|
@@ -7,13 +9,12 @@ from coredis.typing import (
|
|
|
7
9
|
AnyStr,
|
|
8
10
|
ResponsePrimitive,
|
|
9
11
|
ResponseType,
|
|
10
|
-
ValueT,
|
|
11
12
|
)
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
class StringSetCallback(ResponseCallback[AnyStr | None, AnyStr | None, AnyStr | bool | None]):
|
|
15
|
-
def transform(self, response: AnyStr | None, **options:
|
|
16
|
-
if options.get("get"):
|
|
16
|
+
def transform(self, response: AnyStr | None, **options: Any) -> AnyStr | bool | None:
|
|
17
|
+
if self.options.get("get"):
|
|
17
18
|
return response
|
|
18
19
|
else:
|
|
19
20
|
return SimpleStringCallback()(response)
|
|
@@ -23,13 +24,13 @@ class LCSCallback(
|
|
|
23
24
|
ResponseCallback[
|
|
24
25
|
list[ResponseType],
|
|
25
26
|
dict[ResponsePrimitive, ResponseType],
|
|
26
|
-
|
|
27
|
+
LCSResult,
|
|
27
28
|
]
|
|
28
29
|
):
|
|
29
30
|
def transform(
|
|
30
31
|
self,
|
|
31
32
|
response: (list[ResponseType] | dict[ResponsePrimitive, ResponseType]),
|
|
32
|
-
**options:
|
|
33
|
+
**options: Any,
|
|
33
34
|
) -> LCSResult:
|
|
34
35
|
assert (
|
|
35
36
|
isinstance(response, list)
|
|
@@ -52,7 +53,7 @@ class LCSCallback(
|
|
|
52
53
|
def transform_3(
|
|
53
54
|
self,
|
|
54
55
|
response: dict[ResponsePrimitive, ResponseType],
|
|
55
|
-
**options:
|
|
56
|
+
**options: Any,
|
|
56
57
|
) -> LCSResult:
|
|
57
58
|
proxy = EncodingInsensitiveDict(response)
|
|
58
59
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from coredis._utils import nativestr
|
|
4
|
+
from coredis.response._callbacks import ResponseCallback
|
|
5
|
+
from coredis.response._utils import flat_pairs_to_dict
|
|
6
|
+
from coredis.response.types import VectorData
|
|
7
|
+
from coredis.typing import AnyStr, ResponsePrimitive, StringT
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class VSimCallback(
|
|
11
|
+
ResponseCallback[
|
|
12
|
+
list[AnyStr],
|
|
13
|
+
list[AnyStr] | dict[AnyStr, float],
|
|
14
|
+
tuple[AnyStr, ...] | dict[AnyStr, float],
|
|
15
|
+
],
|
|
16
|
+
):
|
|
17
|
+
def transform(
|
|
18
|
+
self,
|
|
19
|
+
response: list[AnyStr],
|
|
20
|
+
) -> tuple[AnyStr, ...] | dict[AnyStr, float]:
|
|
21
|
+
if self.options.get("withscores"):
|
|
22
|
+
it = iter(response)
|
|
23
|
+
return dict(list(zip(it, map(float, it))))
|
|
24
|
+
else:
|
|
25
|
+
return tuple(response)
|
|
26
|
+
|
|
27
|
+
def transform_3(
|
|
28
|
+
self,
|
|
29
|
+
response: list[AnyStr] | dict[AnyStr, float],
|
|
30
|
+
) -> tuple[AnyStr, ...] | dict[AnyStr, float]:
|
|
31
|
+
if self.options.get("withscores"):
|
|
32
|
+
assert isinstance(response, dict)
|
|
33
|
+
return response
|
|
34
|
+
else:
|
|
35
|
+
return tuple(response)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class VLinksCallback(
|
|
39
|
+
ResponseCallback[
|
|
40
|
+
list[list[AnyStr]] | None,
|
|
41
|
+
list[list[AnyStr] | dict[AnyStr, float]] | None,
|
|
42
|
+
tuple[tuple[AnyStr, ...] | dict[AnyStr, float], ...] | None,
|
|
43
|
+
],
|
|
44
|
+
):
|
|
45
|
+
def transform(
|
|
46
|
+
self,
|
|
47
|
+
response: list[list[AnyStr]] | None,
|
|
48
|
+
) -> tuple[tuple[AnyStr, ...] | dict[AnyStr, float], ...] | None:
|
|
49
|
+
if response:
|
|
50
|
+
if self.options.get("withscores"):
|
|
51
|
+
return tuple(dict(zip(it := iter(layer), map(float, it))) for layer in response)
|
|
52
|
+
else:
|
|
53
|
+
return tuple(tuple(layer) for layer in response)
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
def transform_3(
|
|
57
|
+
self,
|
|
58
|
+
response: list[list[AnyStr] | dict[AnyStr, float]] | None,
|
|
59
|
+
) -> tuple[tuple[AnyStr, ...] | dict[AnyStr, float], ...] | None:
|
|
60
|
+
if response:
|
|
61
|
+
if self.options.get("withscores"):
|
|
62
|
+
assert isinstance(response[0], dict)
|
|
63
|
+
return tuple(response)
|
|
64
|
+
else:
|
|
65
|
+
return tuple(tuple(layer) for layer in response)
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class VEmbCallback(
|
|
70
|
+
ResponseCallback[
|
|
71
|
+
list[StringT] | list[ResponsePrimitive],
|
|
72
|
+
list[float] | list[ResponsePrimitive],
|
|
73
|
+
tuple[float, ...] | VectorData | None,
|
|
74
|
+
]
|
|
75
|
+
):
|
|
76
|
+
def transform(
|
|
77
|
+
self,
|
|
78
|
+
response: list[StringT] | list[ResponsePrimitive] | None,
|
|
79
|
+
) -> tuple[float, ...] | VectorData | None:
|
|
80
|
+
if response:
|
|
81
|
+
if self.options.get("raw"):
|
|
82
|
+
return VectorData(
|
|
83
|
+
quantization=nativestr(response[0]),
|
|
84
|
+
blob=response[1],
|
|
85
|
+
l2_norm=float(response[2]),
|
|
86
|
+
quantization_range=float(response[3]) if len(response) == 4 else None,
|
|
87
|
+
)
|
|
88
|
+
else:
|
|
89
|
+
return tuple(map(float, response))
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
def transform_3(
|
|
93
|
+
self,
|
|
94
|
+
response: list[float] | list[ResponsePrimitive] | None,
|
|
95
|
+
) -> tuple[float, ...] | VectorData | None:
|
|
96
|
+
if response:
|
|
97
|
+
if self.options.get("raw"):
|
|
98
|
+
return VectorData(
|
|
99
|
+
quantization=nativestr(response[0]),
|
|
100
|
+
blob=response[1],
|
|
101
|
+
l2_norm=response[2],
|
|
102
|
+
quantization_range=response[3] if len(response) == 4 else None,
|
|
103
|
+
)
|
|
104
|
+
else:
|
|
105
|
+
return tuple(response)
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class VInfoCallback(
|
|
110
|
+
ResponseCallback[
|
|
111
|
+
list[AnyStr | int] | None,
|
|
112
|
+
dict[AnyStr, AnyStr | int] | None,
|
|
113
|
+
dict[AnyStr, AnyStr | int] | None,
|
|
114
|
+
]
|
|
115
|
+
):
|
|
116
|
+
def transform(
|
|
117
|
+
self,
|
|
118
|
+
response: list[AnyStr | int] | None,
|
|
119
|
+
) -> dict[AnyStr, AnyStr | int] | None:
|
|
120
|
+
return flat_pairs_to_dict(response) if response else None
|
|
121
|
+
|
|
122
|
+
def transform_3(
|
|
123
|
+
self,
|
|
124
|
+
response: dict[AnyStr, AnyStr | int] | None,
|
|
125
|
+
) -> dict[AnyStr, AnyStr | int] | None:
|
|
126
|
+
return response
|
coredis/response/types.py
CHANGED
|
@@ -13,9 +13,9 @@ from coredis.typing import (
|
|
|
13
13
|
Mapping,
|
|
14
14
|
NamedTuple,
|
|
15
15
|
OrderedDict,
|
|
16
|
+
RedisValueT,
|
|
16
17
|
StringT,
|
|
17
18
|
TypedDict,
|
|
18
|
-
ValueT,
|
|
19
19
|
)
|
|
20
20
|
|
|
21
21
|
#: Response from `CLIENT INFO <https://redis.io/commands/client-info>`__
|
|
@@ -112,8 +112,6 @@ class LibraryDefinition(TypedDict):
|
|
|
112
112
|
name: StringT
|
|
113
113
|
#: the engine used by the library
|
|
114
114
|
engine: Literal["LUA"]
|
|
115
|
-
#: the library's description
|
|
116
|
-
description: StringT
|
|
117
115
|
#: Mapping of function names to functions in the library
|
|
118
116
|
functions: dict[StringT, FunctionDefinition]
|
|
119
117
|
#: The library's source code
|
|
@@ -371,7 +369,7 @@ class ClusterNodeDetail(TypedDict):
|
|
|
371
369
|
pong_recv: int
|
|
372
370
|
link_state: str
|
|
373
371
|
slots: list[int]
|
|
374
|
-
migrations: list[dict[str,
|
|
372
|
+
migrations: list[dict[str, RedisValueT]]
|
|
375
373
|
|
|
376
374
|
|
|
377
375
|
class PubSubMessage(TypedDict):
|
|
@@ -405,3 +403,14 @@ class PubSubMessage(TypedDict):
|
|
|
405
403
|
#: this will be an :class:`int` corresponding to the number of channels and patterns that the
|
|
406
404
|
#: connection is currently subscribed to.
|
|
407
405
|
data: int | StringT
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class VectorData(TypedDict):
|
|
409
|
+
#: The quantization type as a string (``fp32``, ``bin`` or ``q8``)
|
|
410
|
+
quantization: str
|
|
411
|
+
#: Raw bytes representation of the vector
|
|
412
|
+
blob: bytes
|
|
413
|
+
#: The L2 norm of the vector before normalization
|
|
414
|
+
l2_norm: float
|
|
415
|
+
#: If the vector is quantized as q8, the quantization range
|
|
416
|
+
quantization_range: float
|
coredis/sentinel.py
CHANGED
|
@@ -46,7 +46,7 @@ class SentinelManagedConnection(Connection, Generic[AnyStr]):
|
|
|
46
46
|
socket_keepalive_options: dict[int, int | bytes] | None = None,
|
|
47
47
|
*,
|
|
48
48
|
client_name: str | None = None,
|
|
49
|
-
protocol_version: Literal[2, 3] =
|
|
49
|
+
protocol_version: Literal[2, 3] = 3,
|
|
50
50
|
):
|
|
51
51
|
self.connection_pool: SentinelConnectionPool = weakref.proxy(connection_pool)
|
|
52
52
|
super().__init__(
|
coredis/stream.py
CHANGED
|
@@ -19,6 +19,7 @@ from coredis.typing import (
|
|
|
19
19
|
Generator,
|
|
20
20
|
Generic,
|
|
21
21
|
KeyT,
|
|
22
|
+
MutableMapping,
|
|
22
23
|
Parameters,
|
|
23
24
|
StringT,
|
|
24
25
|
TypedDict,
|
|
@@ -38,7 +39,7 @@ class State(TypedDict, total=False):
|
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
class Consumer(Generic[AnyStr]):
|
|
41
|
-
state:
|
|
42
|
+
state: MutableMapping[KeyT, State]
|
|
42
43
|
DEFAULT_START_ID: ClassVar[bytes] = b"0-0"
|
|
43
44
|
|
|
44
45
|
def __init__(
|
|
@@ -71,10 +72,10 @@ class Consumer(Generic[AnyStr]):
|
|
|
71
72
|
"""
|
|
72
73
|
self.client: Client[AnyStr] = client
|
|
73
74
|
self.streams: set[KeyT] = set(streams)
|
|
74
|
-
self.state:
|
|
75
|
+
self.state: MutableMapping[StringT, State] = EncodingInsensitiveDict(
|
|
75
76
|
{stream: stream_parameters.get(nativestr(stream), {}) for stream in streams}
|
|
76
77
|
)
|
|
77
|
-
self.buffer:
|
|
78
|
+
self.buffer: MutableMapping[AnyStr, list[StreamEntry]] = EncodingInsensitiveDict({})
|
|
78
79
|
self.buffer_size = buffer_size
|
|
79
80
|
self.timeout = timeout
|
|
80
81
|
self._initialized = False
|