coredis 5.5.0__cp313-cp313-macosx_11_0_arm64.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.
- 22fe76227e35f92ab5c3__mypyc.cpython-313-darwin.so +0 -0
- coredis/__init__.py +42 -0
- coredis/_enum.py +42 -0
- coredis/_json.py +11 -0
- coredis/_packer.cpython-313-darwin.so +0 -0
- coredis/_packer.py +71 -0
- coredis/_protocols.py +50 -0
- coredis/_py_311_typing.py +20 -0
- coredis/_py_312_typing.py +17 -0
- coredis/_sidecar.py +114 -0
- coredis/_utils.cpython-313-darwin.so +0 -0
- coredis/_utils.py +440 -0
- coredis/_version.py +34 -0
- coredis/_version.pyi +1 -0
- coredis/cache.py +801 -0
- coredis/client/__init__.py +6 -0
- coredis/client/basic.py +1240 -0
- coredis/client/cluster.py +1265 -0
- coredis/commands/__init__.py +64 -0
- coredis/commands/_key_spec.py +517 -0
- coredis/commands/_utils.py +108 -0
- coredis/commands/_validators.py +159 -0
- coredis/commands/_wrappers.py +175 -0
- coredis/commands/bitfield.py +110 -0
- coredis/commands/constants.py +662 -0
- coredis/commands/core.py +8484 -0
- coredis/commands/function.py +408 -0
- coredis/commands/monitor.py +168 -0
- coredis/commands/pubsub.py +905 -0
- coredis/commands/request.py +108 -0
- coredis/commands/script.py +296 -0
- coredis/commands/sentinel.py +246 -0
- coredis/config.py +50 -0
- coredis/connection.py +906 -0
- coredis/constants.cpython-313-darwin.so +0 -0
- coredis/constants.py +37 -0
- coredis/credentials.py +45 -0
- coredis/exceptions.py +360 -0
- coredis/experimental/__init__.py +1 -0
- coredis/globals.py +23 -0
- coredis/modules/__init__.py +121 -0
- coredis/modules/autocomplete.py +138 -0
- coredis/modules/base.py +262 -0
- coredis/modules/filters.py +1319 -0
- coredis/modules/graph.py +362 -0
- coredis/modules/json.py +691 -0
- coredis/modules/response/__init__.py +0 -0
- coredis/modules/response/_callbacks/__init__.py +0 -0
- coredis/modules/response/_callbacks/autocomplete.py +42 -0
- coredis/modules/response/_callbacks/graph.py +237 -0
- coredis/modules/response/_callbacks/json.py +21 -0
- coredis/modules/response/_callbacks/search.py +221 -0
- coredis/modules/response/_callbacks/timeseries.py +158 -0
- coredis/modules/response/types.py +179 -0
- coredis/modules/search.py +1089 -0
- coredis/modules/timeseries.py +1139 -0
- coredis/parser.cpython-313-darwin.so +0 -0
- coredis/parser.py +344 -0
- coredis/pipeline.py +1225 -0
- coredis/pool/__init__.py +11 -0
- coredis/pool/basic.py +453 -0
- coredis/pool/cluster.py +517 -0
- coredis/pool/nodemanager.py +340 -0
- coredis/py.typed +0 -0
- coredis/recipes/__init__.py +0 -0
- coredis/recipes/credentials/__init__.py +5 -0
- coredis/recipes/credentials/iam_provider.py +63 -0
- coredis/recipes/locks/__init__.py +5 -0
- coredis/recipes/locks/extend.lua +17 -0
- coredis/recipes/locks/lua_lock.py +281 -0
- coredis/recipes/locks/release.lua +10 -0
- coredis/response/__init__.py +5 -0
- coredis/response/_callbacks/__init__.py +538 -0
- coredis/response/_callbacks/acl.py +32 -0
- coredis/response/_callbacks/cluster.py +183 -0
- coredis/response/_callbacks/command.py +86 -0
- coredis/response/_callbacks/connection.py +31 -0
- coredis/response/_callbacks/geo.py +58 -0
- coredis/response/_callbacks/hash.py +85 -0
- coredis/response/_callbacks/keys.py +59 -0
- coredis/response/_callbacks/module.py +33 -0
- coredis/response/_callbacks/script.py +85 -0
- coredis/response/_callbacks/sentinel.py +179 -0
- coredis/response/_callbacks/server.py +241 -0
- coredis/response/_callbacks/sets.py +44 -0
- coredis/response/_callbacks/sorted_set.py +204 -0
- coredis/response/_callbacks/streams.py +185 -0
- coredis/response/_callbacks/strings.py +70 -0
- coredis/response/_callbacks/vector_sets.py +159 -0
- coredis/response/_utils.py +33 -0
- coredis/response/types.py +416 -0
- coredis/retry.py +233 -0
- coredis/sentinel.py +477 -0
- coredis/stream.py +369 -0
- coredis/tokens.py +2286 -0
- coredis/typing.py +593 -0
- coredis-5.5.0.dist-info/METADATA +211 -0
- coredis-5.5.0.dist-info/RECORD +100 -0
- coredis-5.5.0.dist-info/WHEEL +6 -0
- coredis-5.5.0.dist-info/licenses/LICENSE +23 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from coredis._utils import EncodingInsensitiveDict
|
|
6
|
+
from coredis.response._callbacks import ResponseCallback
|
|
7
|
+
from coredis.response._utils import flat_pairs_to_dict, flat_pairs_to_ordered_dict
|
|
8
|
+
from coredis.response.types import (
|
|
9
|
+
StreamEntry,
|
|
10
|
+
StreamInfo,
|
|
11
|
+
StreamPending,
|
|
12
|
+
StreamPendingExt,
|
|
13
|
+
)
|
|
14
|
+
from coredis.typing import (
|
|
15
|
+
AnyStr,
|
|
16
|
+
OrderedDict,
|
|
17
|
+
ResponseType,
|
|
18
|
+
StringT,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class StreamRangeCallback(ResponseCallback[ResponseType, ResponseType, tuple[StreamEntry, ...]]):
|
|
23
|
+
def transform(
|
|
24
|
+
self,
|
|
25
|
+
response: ResponseType,
|
|
26
|
+
) -> tuple[StreamEntry, ...]:
|
|
27
|
+
return tuple(StreamEntry(r[0], flat_pairs_to_ordered_dict(r[1])) for r in response)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ClaimCallback(
|
|
31
|
+
ResponseCallback[ResponseType, ResponseType, tuple[AnyStr, ...] | tuple[StreamEntry, ...]]
|
|
32
|
+
):
|
|
33
|
+
def transform(
|
|
34
|
+
self,
|
|
35
|
+
response: ResponseType,
|
|
36
|
+
) -> tuple[AnyStr, ...] | tuple[StreamEntry, ...]:
|
|
37
|
+
if self.options.get("justid") is not None:
|
|
38
|
+
return tuple(response)
|
|
39
|
+
else:
|
|
40
|
+
return StreamRangeCallback()(response)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AutoClaimCallback(
|
|
44
|
+
ResponseCallback[
|
|
45
|
+
ResponseType,
|
|
46
|
+
ResponseType,
|
|
47
|
+
tuple[AnyStr, tuple[AnyStr, ...]]
|
|
48
|
+
| tuple[AnyStr, tuple[StreamEntry, ...], tuple[AnyStr, ...]],
|
|
49
|
+
]
|
|
50
|
+
):
|
|
51
|
+
def transform(
|
|
52
|
+
self,
|
|
53
|
+
response: ResponseType,
|
|
54
|
+
) -> (
|
|
55
|
+
tuple[AnyStr, tuple[AnyStr, ...]]
|
|
56
|
+
| tuple[AnyStr, tuple[StreamEntry, ...], tuple[AnyStr, ...]]
|
|
57
|
+
):
|
|
58
|
+
if self.options.get("justid") is not None:
|
|
59
|
+
return response[0], tuple(response[1])
|
|
60
|
+
else:
|
|
61
|
+
return (
|
|
62
|
+
response[0],
|
|
63
|
+
StreamRangeCallback()(response[1]),
|
|
64
|
+
tuple(response[2]) if len(response) > 2 else (),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class MultiStreamRangeCallback(
|
|
69
|
+
ResponseCallback[ResponseType, ResponseType, dict[AnyStr, tuple[StreamEntry, ...]] | None]
|
|
70
|
+
):
|
|
71
|
+
def transform_3(
|
|
72
|
+
self,
|
|
73
|
+
response: ResponseType,
|
|
74
|
+
) -> dict[AnyStr, tuple[StreamEntry, ...]] | None:
|
|
75
|
+
if response:
|
|
76
|
+
mapping: dict[AnyStr, tuple[StreamEntry, ...]] = {}
|
|
77
|
+
|
|
78
|
+
for stream_id, entries in response.items():
|
|
79
|
+
mapping[stream_id] = tuple(
|
|
80
|
+
StreamEntry(r[0], flat_pairs_to_ordered_dict(r[1])) for r in entries
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
return mapping
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
def transform(
|
|
87
|
+
self,
|
|
88
|
+
response: ResponseType,
|
|
89
|
+
) -> dict[AnyStr, tuple[StreamEntry, ...]] | None:
|
|
90
|
+
if response:
|
|
91
|
+
mapping: dict[AnyStr, tuple[StreamEntry, ...]] = {}
|
|
92
|
+
|
|
93
|
+
for stream_id, entries in response:
|
|
94
|
+
mapping[stream_id] = tuple(
|
|
95
|
+
StreamEntry(r[0], flat_pairs_to_ordered_dict(r[1])) for r in entries
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return mapping
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class PendingCallback(
|
|
103
|
+
ResponseCallback[ResponseType, ResponseType, StreamPending | tuple[StreamPendingExt, ...]]
|
|
104
|
+
):
|
|
105
|
+
def transform(
|
|
106
|
+
self,
|
|
107
|
+
response: ResponseType,
|
|
108
|
+
) -> StreamPending | tuple[StreamPendingExt, ...]:
|
|
109
|
+
if not self.options.get("count"):
|
|
110
|
+
return StreamPending(
|
|
111
|
+
response[0],
|
|
112
|
+
response[1],
|
|
113
|
+
response[2],
|
|
114
|
+
OrderedDict((r[0], int(r[1])) for r in response[3] or []),
|
|
115
|
+
)
|
|
116
|
+
else:
|
|
117
|
+
return tuple(StreamPendingExt(sub[0], sub[1], sub[2], sub[3]) for sub in response)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class XInfoCallback(ResponseCallback[ResponseType, ResponseType, tuple[dict[AnyStr, AnyStr], ...]]):
|
|
121
|
+
def transform(
|
|
122
|
+
self,
|
|
123
|
+
response: ResponseType,
|
|
124
|
+
) -> tuple[dict[AnyStr, AnyStr], ...]:
|
|
125
|
+
return tuple(flat_pairs_to_dict(row) for row in response)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class StreamInfoCallback(ResponseCallback[ResponseType, ResponseType, StreamInfo]):
|
|
129
|
+
def transform(
|
|
130
|
+
self,
|
|
131
|
+
response: ResponseType,
|
|
132
|
+
) -> StreamInfo:
|
|
133
|
+
res: dict[StringT, Any] = EncodingInsensitiveDict(flat_pairs_to_dict(response))
|
|
134
|
+
if not self.options.get("full"):
|
|
135
|
+
k1 = "first-entry"
|
|
136
|
+
kn = "last-entry"
|
|
137
|
+
e1: StreamEntry | None = None
|
|
138
|
+
en: StreamEntry | None = None
|
|
139
|
+
|
|
140
|
+
if len(res.get(k1, [])) > 0:
|
|
141
|
+
v = res.get(k1)
|
|
142
|
+
e1 = StreamEntry(v[0], flat_pairs_to_ordered_dict(v[1]))
|
|
143
|
+
res.pop(k1)
|
|
144
|
+
|
|
145
|
+
if len(res.get(kn, [])) > 0:
|
|
146
|
+
v = res.get(kn)
|
|
147
|
+
en = StreamEntry(v[0], flat_pairs_to_ordered_dict(v[1]))
|
|
148
|
+
res.pop(kn)
|
|
149
|
+
res.update({"first-entry": e1, "last-entry": en})
|
|
150
|
+
else:
|
|
151
|
+
groups = res.get("groups")
|
|
152
|
+
if groups:
|
|
153
|
+
normalized_groups = []
|
|
154
|
+
for group in groups:
|
|
155
|
+
g = EncodingInsensitiveDict(flat_pairs_to_dict(group))
|
|
156
|
+
consumers = g["consumers"]
|
|
157
|
+
normalized_consumers = []
|
|
158
|
+
for consumer in consumers:
|
|
159
|
+
normalized_consumers.append(flat_pairs_to_dict(consumer))
|
|
160
|
+
g["consumers"] = normalized_consumers
|
|
161
|
+
normalized_groups.append(g)
|
|
162
|
+
res["groups"] = normalized_groups
|
|
163
|
+
res.update(
|
|
164
|
+
{
|
|
165
|
+
"entries": tuple(
|
|
166
|
+
StreamEntry(k[0], flat_pairs_to_ordered_dict(k[1]))
|
|
167
|
+
for k in res.get("entries", [])
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
stream_info: StreamInfo = {
|
|
172
|
+
"first-entry": res.get("first-entry"),
|
|
173
|
+
"last-entry": res.get("last-entry"),
|
|
174
|
+
"length": res["length"],
|
|
175
|
+
"radix-tree-keys": res["radix-tree-keys"],
|
|
176
|
+
"radix-tree-nodes": res["radix-tree-nodes"],
|
|
177
|
+
"groups": res["groups"],
|
|
178
|
+
"last-generated-id": res["last-generated-id"],
|
|
179
|
+
"max-deleted-entry-id": str(res.get("max-deleted-entry-id")),
|
|
180
|
+
"entries-added": int(res.get("entries-added", 0)),
|
|
181
|
+
"recorded-first-entry-id": str(res.get("recorded-first-entry-id")),
|
|
182
|
+
"entries-read": int(res.get("entries-read", 0)),
|
|
183
|
+
"entries": res.get("entries"),
|
|
184
|
+
}
|
|
185
|
+
return stream_info
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from coredis._utils import EncodingInsensitiveDict
|
|
6
|
+
from coredis.response._callbacks import ResponseCallback, SimpleStringCallback
|
|
7
|
+
from coredis.response.types import LCSMatch, LCSResult
|
|
8
|
+
from coredis.typing import (
|
|
9
|
+
AnyStr,
|
|
10
|
+
ResponsePrimitive,
|
|
11
|
+
ResponseType,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class StringSetCallback(ResponseCallback[AnyStr | None, AnyStr | None, AnyStr | bool | None]):
|
|
16
|
+
def transform(self, response: AnyStr | None, **options: Any) -> AnyStr | bool | None:
|
|
17
|
+
if self.options.get("get"):
|
|
18
|
+
return response
|
|
19
|
+
else:
|
|
20
|
+
return SimpleStringCallback()(response)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class LCSCallback(
|
|
24
|
+
ResponseCallback[
|
|
25
|
+
list[ResponseType],
|
|
26
|
+
dict[ResponsePrimitive, ResponseType],
|
|
27
|
+
LCSResult,
|
|
28
|
+
]
|
|
29
|
+
):
|
|
30
|
+
def transform(
|
|
31
|
+
self,
|
|
32
|
+
response: (list[ResponseType] | dict[ResponsePrimitive, ResponseType]),
|
|
33
|
+
**options: Any,
|
|
34
|
+
) -> LCSResult:
|
|
35
|
+
assert (
|
|
36
|
+
isinstance(response, list)
|
|
37
|
+
and isinstance(response[-1], int)
|
|
38
|
+
and isinstance(response[1], list)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return LCSResult(
|
|
42
|
+
tuple(
|
|
43
|
+
LCSMatch(
|
|
44
|
+
(int(k[0][0]), int(k[0][1])),
|
|
45
|
+
(int(k[1][0]), int(k[1][1])),
|
|
46
|
+
k[2] if len(k) > 2 else None,
|
|
47
|
+
)
|
|
48
|
+
for k in response[1]
|
|
49
|
+
),
|
|
50
|
+
response[-1],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def transform_3(
|
|
54
|
+
self,
|
|
55
|
+
response: dict[ResponsePrimitive, ResponseType],
|
|
56
|
+
**options: Any,
|
|
57
|
+
) -> LCSResult:
|
|
58
|
+
proxy = EncodingInsensitiveDict(response)
|
|
59
|
+
|
|
60
|
+
return LCSResult(
|
|
61
|
+
tuple(
|
|
62
|
+
LCSMatch(
|
|
63
|
+
(int(k[0][0]), int(k[0][1])),
|
|
64
|
+
(int(k[1][0]), int(k[1][1])),
|
|
65
|
+
k[2] if len(k) > 2 else None,
|
|
66
|
+
)
|
|
67
|
+
for k in proxy["matches"]
|
|
68
|
+
),
|
|
69
|
+
proxy["len"],
|
|
70
|
+
)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from coredis._json import json
|
|
4
|
+
from coredis._utils import nativestr
|
|
5
|
+
from coredis.response._callbacks import ResponseCallback
|
|
6
|
+
from coredis.response._utils import flat_pairs_to_dict
|
|
7
|
+
from coredis.response.types import VectorData
|
|
8
|
+
from coredis.typing import AnyStr, JsonType, ResponsePrimitive, StringT
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class VSimCallback(
|
|
12
|
+
ResponseCallback[
|
|
13
|
+
list[AnyStr],
|
|
14
|
+
list[AnyStr] | dict[AnyStr, float | list[float | JsonType]],
|
|
15
|
+
tuple[AnyStr, ...]
|
|
16
|
+
| dict[AnyStr, float]
|
|
17
|
+
| dict[AnyStr, JsonType]
|
|
18
|
+
| dict[AnyStr, tuple[float, JsonType]],
|
|
19
|
+
],
|
|
20
|
+
):
|
|
21
|
+
def transform(
|
|
22
|
+
self,
|
|
23
|
+
response: list[AnyStr],
|
|
24
|
+
) -> (
|
|
25
|
+
tuple[AnyStr, ...]
|
|
26
|
+
| dict[AnyStr, float]
|
|
27
|
+
| dict[AnyStr, JsonType]
|
|
28
|
+
| dict[AnyStr, tuple[float, JsonType]]
|
|
29
|
+
):
|
|
30
|
+
withscores, withattribs = self.options.get("withscores"), self.options.get("withattribs")
|
|
31
|
+
if withscores or withattribs:
|
|
32
|
+
it = iter(response)
|
|
33
|
+
match withscores, withattribs:
|
|
34
|
+
case True, None | False:
|
|
35
|
+
return dict(list(zip(it, map(float, it))))
|
|
36
|
+
case None | False, True:
|
|
37
|
+
return dict(list(zip(it, map(json.loads, it))))
|
|
38
|
+
case True, True:
|
|
39
|
+
return dict(
|
|
40
|
+
list(zip(it, map(lambda x: (float(x[0]), json.loads(x[1])), zip(it, it))))
|
|
41
|
+
)
|
|
42
|
+
else:
|
|
43
|
+
return self.transform_3(response)
|
|
44
|
+
|
|
45
|
+
def transform_3(
|
|
46
|
+
self,
|
|
47
|
+
response: list[AnyStr]
|
|
48
|
+
| dict[AnyStr, float]
|
|
49
|
+
| dict[AnyStr, AnyStr]
|
|
50
|
+
| dict[AnyStr, list[float | AnyStr]],
|
|
51
|
+
) -> (
|
|
52
|
+
tuple[AnyStr, ...]
|
|
53
|
+
| dict[AnyStr, float]
|
|
54
|
+
| dict[AnyStr, JsonType]
|
|
55
|
+
| dict[AnyStr, tuple[float, JsonType]]
|
|
56
|
+
):
|
|
57
|
+
withscores, withattribs = self.options.get("withscores"), self.options.get("withattribs")
|
|
58
|
+
if withscores or withattribs:
|
|
59
|
+
assert isinstance(response, dict)
|
|
60
|
+
match withscores, withattribs:
|
|
61
|
+
case None | False, True:
|
|
62
|
+
return {k: json.loads(v) for k, v in response.items()}
|
|
63
|
+
case True, True:
|
|
64
|
+
return {k: (v[0], json.loads(v[1])) for k, v in response.items()}
|
|
65
|
+
case _:
|
|
66
|
+
return response
|
|
67
|
+
else:
|
|
68
|
+
return tuple(response)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class VLinksCallback(
|
|
72
|
+
ResponseCallback[
|
|
73
|
+
list[list[AnyStr]] | None,
|
|
74
|
+
list[list[AnyStr] | dict[AnyStr, float]] | None,
|
|
75
|
+
tuple[tuple[AnyStr, ...] | dict[AnyStr, float], ...] | None,
|
|
76
|
+
],
|
|
77
|
+
):
|
|
78
|
+
def transform(
|
|
79
|
+
self,
|
|
80
|
+
response: list[list[AnyStr]] | None,
|
|
81
|
+
) -> tuple[tuple[AnyStr, ...] | dict[AnyStr, float], ...] | None:
|
|
82
|
+
if response:
|
|
83
|
+
if self.options.get("withscores"):
|
|
84
|
+
return tuple(dict(zip(it := iter(layer), map(float, it))) for layer in response)
|
|
85
|
+
else:
|
|
86
|
+
return tuple(tuple(layer) for layer in response)
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
def transform_3(
|
|
90
|
+
self,
|
|
91
|
+
response: list[list[AnyStr] | dict[AnyStr, float]] | None,
|
|
92
|
+
) -> tuple[tuple[AnyStr, ...] | dict[AnyStr, float], ...] | None:
|
|
93
|
+
if response:
|
|
94
|
+
if self.options.get("withscores"):
|
|
95
|
+
assert isinstance(response[0], dict)
|
|
96
|
+
return tuple(response)
|
|
97
|
+
else:
|
|
98
|
+
return tuple(tuple(layer) for layer in response)
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class VEmbCallback(
|
|
103
|
+
ResponseCallback[
|
|
104
|
+
list[StringT] | list[ResponsePrimitive],
|
|
105
|
+
list[float] | list[ResponsePrimitive],
|
|
106
|
+
tuple[float, ...] | VectorData | None,
|
|
107
|
+
]
|
|
108
|
+
):
|
|
109
|
+
def transform(
|
|
110
|
+
self,
|
|
111
|
+
response: list[StringT] | list[ResponsePrimitive] | None,
|
|
112
|
+
) -> tuple[float, ...] | VectorData | None:
|
|
113
|
+
if response:
|
|
114
|
+
if self.options.get("raw"):
|
|
115
|
+
return VectorData(
|
|
116
|
+
quantization=nativestr(response[0]),
|
|
117
|
+
blob=response[1],
|
|
118
|
+
l2_norm=float(response[2]),
|
|
119
|
+
quantization_range=float(response[3]) if len(response) == 4 else None,
|
|
120
|
+
)
|
|
121
|
+
else:
|
|
122
|
+
return tuple(map(float, response))
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
def transform_3(
|
|
126
|
+
self,
|
|
127
|
+
response: list[float] | list[ResponsePrimitive] | None,
|
|
128
|
+
) -> tuple[float, ...] | VectorData | None:
|
|
129
|
+
if response:
|
|
130
|
+
if self.options.get("raw"):
|
|
131
|
+
return VectorData(
|
|
132
|
+
quantization=nativestr(response[0]),
|
|
133
|
+
blob=response[1],
|
|
134
|
+
l2_norm=response[2],
|
|
135
|
+
quantization_range=response[3] if len(response) == 4 else None,
|
|
136
|
+
)
|
|
137
|
+
else:
|
|
138
|
+
return tuple(response)
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class VInfoCallback(
|
|
143
|
+
ResponseCallback[
|
|
144
|
+
list[AnyStr | int] | None,
|
|
145
|
+
dict[AnyStr, AnyStr | int] | None,
|
|
146
|
+
dict[AnyStr, AnyStr | int] | None,
|
|
147
|
+
]
|
|
148
|
+
):
|
|
149
|
+
def transform(
|
|
150
|
+
self,
|
|
151
|
+
response: list[AnyStr | int] | None,
|
|
152
|
+
) -> dict[AnyStr, AnyStr | int] | None:
|
|
153
|
+
return flat_pairs_to_dict(response) if response else None
|
|
154
|
+
|
|
155
|
+
def transform_3(
|
|
156
|
+
self,
|
|
157
|
+
response: dict[AnyStr, AnyStr | int] | None,
|
|
158
|
+
) -> dict[AnyStr, AnyStr | int] | None:
|
|
159
|
+
return response
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import cast
|
|
4
|
+
|
|
5
|
+
from coredis.typing import (
|
|
6
|
+
Callable,
|
|
7
|
+
Iterable,
|
|
8
|
+
OrderedDict,
|
|
9
|
+
StringT,
|
|
10
|
+
TypeVar,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
T_co = TypeVar("T_co")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def flat_pairs_to_dict(
|
|
17
|
+
response: tuple[T_co, ...] | list[T_co],
|
|
18
|
+
value_transform: Callable[..., T_co] | None = None,
|
|
19
|
+
) -> dict[T_co, T_co]:
|
|
20
|
+
"""Creates a dict given a flat list of key/value pairs"""
|
|
21
|
+
if isinstance(response, dict):
|
|
22
|
+
return response
|
|
23
|
+
it = iter(response)
|
|
24
|
+
if value_transform:
|
|
25
|
+
return dict(zip(it, map(value_transform, it)))
|
|
26
|
+
else:
|
|
27
|
+
return dict(zip(it, it))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def flat_pairs_to_ordered_dict(response: Iterable[T_co]) -> OrderedDict[StringT, T_co]:
|
|
31
|
+
"""Creates a dict given a flat list of key/value pairs"""
|
|
32
|
+
it = iter(response)
|
|
33
|
+
return cast(OrderedDict[StringT, T_co], OrderedDict(zip(it, it)))
|