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
|
@@ -8,13 +8,13 @@ from coredis.typing import (
|
|
|
8
8
|
AnyStr,
|
|
9
9
|
ResponsePrimitive,
|
|
10
10
|
ResponseType,
|
|
11
|
-
ValueT,
|
|
12
11
|
)
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
class CommandCallback(ResponseCallback[list[ResponseType], list[ResponseType], dict[str, Command]]):
|
|
16
15
|
def transform(
|
|
17
|
-
self,
|
|
16
|
+
self,
|
|
17
|
+
response: list[ResponseType],
|
|
18
18
|
) -> dict[str, Command]:
|
|
19
19
|
commands: dict[str, Command] = {}
|
|
20
20
|
|
|
@@ -53,7 +53,8 @@ class CommandKeyFlagCallback(
|
|
|
53
53
|
ResponseCallback[list[ResponseType], list[ResponseType], dict[AnyStr, set[AnyStr]]]
|
|
54
54
|
):
|
|
55
55
|
def transform(
|
|
56
|
-
self,
|
|
56
|
+
self,
|
|
57
|
+
response: list[ResponseType],
|
|
57
58
|
) -> dict[AnyStr, set[AnyStr]]:
|
|
58
59
|
return {k[0]: set(k[1]) for k in response}
|
|
59
60
|
|
|
@@ -66,7 +67,8 @@ class CommandDocCallback(
|
|
|
66
67
|
]
|
|
67
68
|
):
|
|
68
69
|
def transform(
|
|
69
|
-
self,
|
|
70
|
+
self,
|
|
71
|
+
response: list[ResponseType],
|
|
70
72
|
) -> dict[AnyStr, dict[AnyStr, ResponseType]]:
|
|
71
73
|
cmd_mapping = flat_pairs_to_dict(response)
|
|
72
74
|
for cmd, doc in cmd_mapping.items():
|
|
@@ -74,11 +76,11 @@ class CommandDocCallback(
|
|
|
74
76
|
cmd_mapping[cmd]["arguments"] = [
|
|
75
77
|
flat_pairs_to_dict(arg) for arg in cmd_mapping[cmd].get("arguments", [])
|
|
76
78
|
]
|
|
77
|
-
|
|
79
|
+
cmd_mapping[cmd] = dict(cmd_mapping[cmd])
|
|
80
|
+
return dict(cmd_mapping)
|
|
78
81
|
|
|
79
82
|
def transform_3(
|
|
80
83
|
self,
|
|
81
84
|
response: dict[ResponsePrimitive, ResponseType],
|
|
82
|
-
**options: ValueT | None,
|
|
83
85
|
) -> dict[AnyStr, dict[AnyStr, ResponseType]]:
|
|
84
86
|
return response # noqa
|
|
@@ -6,7 +6,6 @@ from coredis.response._utils import flat_pairs_to_dict
|
|
|
6
6
|
from coredis.typing import (
|
|
7
7
|
AnyStr,
|
|
8
8
|
ResponseType,
|
|
9
|
-
ValueT,
|
|
10
9
|
)
|
|
11
10
|
|
|
12
11
|
|
|
@@ -18,13 +17,15 @@ class ClientTrackingInfoCallback(
|
|
|
18
17
|
]
|
|
19
18
|
):
|
|
20
19
|
def transform(
|
|
21
|
-
self,
|
|
20
|
+
self,
|
|
21
|
+
response: ResponseType,
|
|
22
22
|
) -> dict[AnyStr, AnyStr | set[AnyStr] | list[AnyStr]]:
|
|
23
23
|
response = EncodingInsensitiveDict(flat_pairs_to_dict(response))
|
|
24
24
|
response["flags"] = set(response["flags"])
|
|
25
25
|
return dict(response)
|
|
26
26
|
|
|
27
27
|
def transform_3(
|
|
28
|
-
self,
|
|
28
|
+
self,
|
|
29
|
+
response: ResponseType,
|
|
29
30
|
) -> dict[AnyStr, AnyStr | set[AnyStr] | list[AnyStr]]:
|
|
30
31
|
return response
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
3
5
|
from coredis.response._callbacks import ResponseCallback
|
|
4
6
|
from coredis.response.types import GeoCoordinates, GeoSearchResult
|
|
5
|
-
from coredis.typing import AnyStr,
|
|
7
|
+
from coredis.typing import AnyStr, Generic, ResponseType
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class GeoSearchCallback(
|
|
11
|
+
Generic[AnyStr],
|
|
9
12
|
ResponseCallback[
|
|
10
13
|
ResponseType,
|
|
11
14
|
ResponseType,
|
|
12
|
-
|
|
13
|
-
]
|
|
15
|
+
tuple[AnyStr | GeoSearchResult, ...],
|
|
16
|
+
],
|
|
14
17
|
):
|
|
15
18
|
def transform(
|
|
16
|
-
self, response: ResponseType, **options:
|
|
17
|
-
) ->
|
|
18
|
-
if
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
self, response: ResponseType, **options: Any
|
|
20
|
+
) -> tuple[AnyStr | GeoSearchResult, ...]:
|
|
21
|
+
if not (
|
|
22
|
+
self.options.get("withdist")
|
|
23
|
+
or self.options.get("withcoord")
|
|
24
|
+
or self.options.get("withhash")
|
|
25
|
+
):
|
|
22
26
|
return tuple(list(response))
|
|
23
27
|
|
|
24
28
|
results: list[GeoSearchResult] = []
|
|
@@ -27,11 +31,11 @@ class GeoSearchCallback(
|
|
|
27
31
|
results.append(
|
|
28
32
|
GeoSearchResult(
|
|
29
33
|
result.pop(0),
|
|
30
|
-
float(result.pop(0)) if options.get("withdist") else None,
|
|
31
|
-
result.pop(0) if options.get("withhash") else None,
|
|
34
|
+
float(result.pop(0)) if self.options.get("withdist") else None,
|
|
35
|
+
result.pop(0) if self.options.get("withhash") else None,
|
|
32
36
|
(
|
|
33
37
|
GeoCoordinates(*map(float, result.pop(0)))
|
|
34
|
-
if options.get("withcoord")
|
|
38
|
+
if self.options.get("withcoord")
|
|
35
39
|
else None
|
|
36
40
|
),
|
|
37
41
|
)
|
|
@@ -44,7 +48,7 @@ class GeoCoordinatessCallback(
|
|
|
44
48
|
ResponseCallback[ResponseType, ResponseType, tuple[GeoCoordinates | None, ...]]
|
|
45
49
|
):
|
|
46
50
|
def transform(
|
|
47
|
-
self, response: ResponseType, **options:
|
|
51
|
+
self, response: ResponseType, **options: Any
|
|
48
52
|
) -> tuple[GeoCoordinates | None, ...]:
|
|
49
53
|
return tuple(
|
|
50
54
|
map(
|
|
@@ -9,7 +9,6 @@ from coredis.typing import (
|
|
|
9
9
|
ResponseType,
|
|
10
10
|
StringT,
|
|
11
11
|
TypeGuard,
|
|
12
|
-
ValueT,
|
|
13
12
|
)
|
|
14
13
|
|
|
15
14
|
|
|
@@ -24,11 +23,12 @@ class HScanCallback(
|
|
|
24
23
|
return isinstance(response[0], (str, bytes)) and isinstance(response[1], list)
|
|
25
24
|
|
|
26
25
|
def transform(
|
|
27
|
-
self,
|
|
26
|
+
self,
|
|
27
|
+
response: list[ResponseType],
|
|
28
28
|
) -> tuple[int, dict[AnyStr, AnyStr] | tuple[AnyStr, ...]]:
|
|
29
29
|
assert self.guard(response)
|
|
30
30
|
cursor, r = response
|
|
31
|
-
if options.get("novalues"):
|
|
31
|
+
if self.options.get("novalues"):
|
|
32
32
|
return int(cursor), tuple(r)
|
|
33
33
|
else:
|
|
34
34
|
return int(cursor), flat_pairs_to_dict(r)
|
|
@@ -44,13 +44,12 @@ class HRandFieldCallback(
|
|
|
44
44
|
def transform(
|
|
45
45
|
self,
|
|
46
46
|
response: AnyStr | list[AnyStr] | None,
|
|
47
|
-
**options: ValueT | None,
|
|
48
47
|
) -> AnyStr | tuple[AnyStr, ...] | dict[AnyStr, AnyStr] | None:
|
|
49
48
|
if not response:
|
|
50
49
|
return None
|
|
51
|
-
if options.get("count"):
|
|
50
|
+
if self.options.get("count"):
|
|
52
51
|
assert isinstance(response, list)
|
|
53
|
-
if options.get("withvalues"):
|
|
52
|
+
if self.options.get("withvalues"):
|
|
54
53
|
return flat_pairs_to_dict(response)
|
|
55
54
|
else:
|
|
56
55
|
return tuple(response)
|
|
@@ -60,13 +59,12 @@ class HRandFieldCallback(
|
|
|
60
59
|
def transform_3(
|
|
61
60
|
self,
|
|
62
61
|
response: AnyStr | list[AnyStr] | list[list[AnyStr]] | None,
|
|
63
|
-
**options: ValueT | None,
|
|
64
62
|
) -> AnyStr | tuple[AnyStr, ...] | dict[AnyStr, AnyStr] | None:
|
|
65
63
|
if not response:
|
|
66
64
|
return None
|
|
67
|
-
if options.get("count"):
|
|
65
|
+
if self.options.get("count"):
|
|
68
66
|
assert isinstance(response, list)
|
|
69
|
-
if options.get("withvalues"):
|
|
67
|
+
if self.options.get("withvalues"):
|
|
70
68
|
return dict(cast(list[tuple[AnyStr, AnyStr]], response))
|
|
71
69
|
return tuple(cast(tuple[AnyStr, AnyStr], response))
|
|
72
70
|
assert isinstance(response, (str, bytes))
|
|
@@ -74,10 +72,14 @@ class HRandFieldCallback(
|
|
|
74
72
|
|
|
75
73
|
|
|
76
74
|
class HGetAllCallback(ResponseCallback[list[AnyStr], dict[AnyStr, AnyStr], dict[AnyStr, AnyStr]]):
|
|
77
|
-
def transform(
|
|
75
|
+
def transform(
|
|
76
|
+
self,
|
|
77
|
+
response: list[AnyStr],
|
|
78
|
+
) -> dict[AnyStr, AnyStr]:
|
|
78
79
|
return flat_pairs_to_dict(response) if response else {}
|
|
79
80
|
|
|
80
81
|
def transform_3(
|
|
81
|
-
self,
|
|
82
|
+
self,
|
|
83
|
+
response: dict[AnyStr, AnyStr],
|
|
82
84
|
) -> dict[AnyStr, AnyStr]:
|
|
83
85
|
return response
|
|
@@ -9,7 +9,6 @@ from coredis.typing import (
|
|
|
9
9
|
ResponseType,
|
|
10
10
|
StringT,
|
|
11
11
|
TypeGuard,
|
|
12
|
-
ValueT,
|
|
13
12
|
)
|
|
14
13
|
|
|
15
14
|
|
|
@@ -21,7 +20,8 @@ class SortCallback(
|
|
|
21
20
|
]
|
|
22
21
|
):
|
|
23
22
|
def transform(
|
|
24
|
-
self,
|
|
23
|
+
self,
|
|
24
|
+
response: int | list[AnyStr],
|
|
25
25
|
) -> int | tuple[AnyStr, ...]:
|
|
26
26
|
if isinstance(response, list):
|
|
27
27
|
return tuple(response)
|
|
@@ -35,7 +35,8 @@ class ScanCallback(
|
|
|
35
35
|
return isinstance(response[0], (str, bytes)) and isinstance(response[1], list)
|
|
36
36
|
|
|
37
37
|
def transform(
|
|
38
|
-
self,
|
|
38
|
+
self,
|
|
39
|
+
response: list[ResponseType],
|
|
39
40
|
) -> tuple[int, tuple[AnyStr, ...]]:
|
|
40
41
|
assert self.guard(response)
|
|
41
42
|
cursor, r = response
|
|
@@ -43,9 +44,12 @@ class ScanCallback(
|
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
class ExpiryCallback(DateTimeCallback):
|
|
46
|
-
def transform(
|
|
47
|
+
def transform(
|
|
48
|
+
self,
|
|
49
|
+
response: int,
|
|
50
|
+
) -> datetime:
|
|
47
51
|
if response > 0:
|
|
48
|
-
return super().transform(response
|
|
52
|
+
return super().transform(response)
|
|
49
53
|
else:
|
|
50
54
|
if response == -2:
|
|
51
55
|
raise NoKeyError()
|
|
@@ -8,7 +8,6 @@ from coredis.typing import (
|
|
|
8
8
|
AnyStr,
|
|
9
9
|
ResponsePrimitive,
|
|
10
10
|
ResponseType,
|
|
11
|
-
ValueT,
|
|
12
11
|
)
|
|
13
12
|
|
|
14
13
|
|
|
@@ -20,7 +19,8 @@ class ModuleInfoCallback(
|
|
|
20
19
|
]
|
|
21
20
|
):
|
|
22
21
|
def transform(
|
|
23
|
-
self,
|
|
22
|
+
self,
|
|
23
|
+
response: list[list[ResponseType]],
|
|
24
24
|
) -> tuple[dict[AnyStr, ResponsePrimitive], ...]:
|
|
25
25
|
return tuple(
|
|
26
26
|
cast(dict[AnyStr, ResponsePrimitive], flat_pairs_to_dict(mod)) for mod in response
|
|
@@ -29,6 +29,5 @@ class ModuleInfoCallback(
|
|
|
29
29
|
def transform_3(
|
|
30
30
|
self,
|
|
31
31
|
response: list[dict[AnyStr, ResponsePrimitive]],
|
|
32
|
-
**options: ValueT | None,
|
|
33
32
|
) -> tuple[dict[AnyStr, ResponsePrimitive], ...]:
|
|
34
33
|
return tuple(response)
|
|
@@ -9,9 +9,9 @@ from coredis.response.types import LibraryDefinition
|
|
|
9
9
|
from coredis.typing import (
|
|
10
10
|
AnyStr,
|
|
11
11
|
Mapping,
|
|
12
|
+
RedisValueT,
|
|
12
13
|
ResponsePrimitive,
|
|
13
14
|
ResponseType,
|
|
14
|
-
ValueT,
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
|
|
@@ -19,10 +19,11 @@ class FunctionListCallback(
|
|
|
19
19
|
ResponseCallback[list[ResponseType], list[ResponseType], Mapping[AnyStr, LibraryDefinition]]
|
|
20
20
|
):
|
|
21
21
|
def transform(
|
|
22
|
-
self,
|
|
22
|
+
self,
|
|
23
|
+
response: list[ResponseType],
|
|
23
24
|
) -> Mapping[AnyStr, LibraryDefinition]:
|
|
24
25
|
libraries = [
|
|
25
|
-
EncodingInsensitiveDict(flat_pairs_to_dict(cast(list[
|
|
26
|
+
EncodingInsensitiveDict(flat_pairs_to_dict(cast(list[RedisValueT], library)))
|
|
26
27
|
for library in response
|
|
27
28
|
]
|
|
28
29
|
transformed = EncodingInsensitiveDict()
|
|
@@ -36,11 +37,10 @@ class FunctionListCallback(
|
|
|
36
37
|
library["functions"] = functions
|
|
37
38
|
transformed[lib_name] = EncodingInsensitiveDict(
|
|
38
39
|
LibraryDefinition(
|
|
39
|
-
name=library["
|
|
40
|
+
name=library["library_name"],
|
|
40
41
|
engine=library["engine"],
|
|
41
|
-
description=library["description"],
|
|
42
42
|
functions=library["functions"],
|
|
43
|
-
library_code=library
|
|
43
|
+
library_code=library.get("library_code", None),
|
|
44
44
|
)
|
|
45
45
|
)
|
|
46
46
|
return transformed
|
|
@@ -62,7 +62,6 @@ class FunctionStatsCallback(
|
|
|
62
62
|
def transform(
|
|
63
63
|
self,
|
|
64
64
|
response: list[ResponseType],
|
|
65
|
-
**options: ValueT | None,
|
|
66
65
|
) -> dict[AnyStr, AnyStr | dict[AnyStr, dict[AnyStr, ResponsePrimitive]] | None]:
|
|
67
66
|
transformed = flat_pairs_to_dict(response)
|
|
68
67
|
key = cast(AnyStr, b"engines" if b"engines" in transformed else "engines")
|
|
@@ -82,6 +81,5 @@ class FunctionStatsCallback(
|
|
|
82
81
|
AnyStr,
|
|
83
82
|
AnyStr | dict[AnyStr, dict[AnyStr, ResponsePrimitive]] | None,
|
|
84
83
|
],
|
|
85
|
-
**options: ValueT | None,
|
|
86
84
|
) -> dict[AnyStr, AnyStr | dict[AnyStr, dict[AnyStr, ResponsePrimitive]] | None]:
|
|
87
85
|
return response
|
|
@@ -7,9 +7,9 @@ from coredis.response._callbacks import ResponseCallback
|
|
|
7
7
|
from coredis.response._callbacks.server import InfoCallback
|
|
8
8
|
from coredis.typing import (
|
|
9
9
|
AnyStr,
|
|
10
|
+
MutableMapping,
|
|
10
11
|
ResponsePrimitive,
|
|
11
12
|
ResponseType,
|
|
12
|
-
ValueT,
|
|
13
13
|
)
|
|
14
14
|
|
|
15
15
|
SENTINEL_STATE_INT_FIELDS = {
|
|
@@ -54,8 +54,8 @@ def sentinel_state_typed(
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
def add_flags(
|
|
57
|
-
result:
|
|
58
|
-
) ->
|
|
57
|
+
result: MutableMapping[str, int | str | bool],
|
|
58
|
+
) -> MutableMapping[str, int | str | bool]:
|
|
59
59
|
flags = set(nativestr(result["flags"]).split(","))
|
|
60
60
|
for name, flag in (
|
|
61
61
|
("is_master", "master"),
|
|
@@ -72,7 +72,7 @@ def add_flags(
|
|
|
72
72
|
|
|
73
73
|
def parse_sentinel_state(
|
|
74
74
|
item: list[ResponsePrimitive],
|
|
75
|
-
) ->
|
|
75
|
+
) -> MutableMapping[str, int | str | bool]:
|
|
76
76
|
result = sentinel_state_typed([nativestr(k) for k in item])
|
|
77
77
|
result = add_flags(result)
|
|
78
78
|
return result
|
|
@@ -86,16 +86,16 @@ class PrimaryCallback(
|
|
|
86
86
|
]
|
|
87
87
|
):
|
|
88
88
|
def transform(
|
|
89
|
-
self,
|
|
89
|
+
self,
|
|
90
|
+
response: ResponseType,
|
|
90
91
|
) -> dict[str, str | int | bool]:
|
|
91
|
-
return parse_sentinel_state(cast(list[ResponsePrimitive], response))
|
|
92
|
+
return dict(parse_sentinel_state(cast(list[ResponsePrimitive], response)))
|
|
92
93
|
|
|
93
94
|
def transform_3(
|
|
94
95
|
self,
|
|
95
96
|
response: dict[ResponsePrimitive, ResponsePrimitive],
|
|
96
|
-
**options: ValueT | None,
|
|
97
97
|
) -> dict[str, str | int | bool]:
|
|
98
|
-
return add_flags(EncodingInsensitiveDict(response))
|
|
98
|
+
return dict(add_flags(EncodingInsensitiveDict(response)))
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
class PrimariesCallback(
|
|
@@ -108,7 +108,6 @@ class PrimariesCallback(
|
|
|
108
108
|
def transform(
|
|
109
109
|
self,
|
|
110
110
|
response: list[ResponseType] | dict[ResponsePrimitive, ResponsePrimitive],
|
|
111
|
-
**options: ValueT | None,
|
|
112
111
|
) -> dict[str, dict[str, str | int | bool]]:
|
|
113
112
|
result: dict[str, dict[str, str | int | bool]] = {}
|
|
114
113
|
|
|
@@ -119,12 +118,13 @@ class PrimariesCallback(
|
|
|
119
118
|
return result
|
|
120
119
|
|
|
121
120
|
def transform_3(
|
|
122
|
-
self,
|
|
121
|
+
self,
|
|
122
|
+
response: list[ResponseType],
|
|
123
123
|
) -> dict[str, dict[str, str | int | bool]]:
|
|
124
124
|
states: dict[str, dict[str, str | int | bool]] = {}
|
|
125
125
|
for state in response:
|
|
126
126
|
proxy = add_flags(EncodingInsensitiveDict(state))
|
|
127
|
-
states[nativestr(proxy["name"])] = proxy
|
|
127
|
+
states[nativestr(proxy["name"])] = dict(proxy)
|
|
128
128
|
return states
|
|
129
129
|
|
|
130
130
|
|
|
@@ -136,14 +136,16 @@ class SentinelsStateCallback(
|
|
|
136
136
|
]
|
|
137
137
|
):
|
|
138
138
|
def transform(
|
|
139
|
-
self,
|
|
139
|
+
self,
|
|
140
|
+
response: list[ResponseType],
|
|
140
141
|
) -> tuple[dict[str, str | bool | int], ...]:
|
|
141
|
-
return tuple(parse_sentinel_state([nativestr(i) for i in item]) for item in response)
|
|
142
|
+
return tuple(dict(parse_sentinel_state([nativestr(i) for i in item])) for item in response)
|
|
142
143
|
|
|
143
144
|
def transform_3(
|
|
144
|
-
self,
|
|
145
|
+
self,
|
|
146
|
+
response: list[ResponseType],
|
|
145
147
|
) -> tuple[dict[str, str | bool | int], ...]:
|
|
146
|
-
return tuple(add_flags(EncodingInsensitiveDict(state)) for state in response)
|
|
148
|
+
return tuple(dict(add_flags(EncodingInsensitiveDict(state))) for state in response)
|
|
147
149
|
|
|
148
150
|
|
|
149
151
|
class GetPrimaryCallback(
|
|
@@ -154,7 +156,8 @@ class GetPrimaryCallback(
|
|
|
154
156
|
]
|
|
155
157
|
):
|
|
156
158
|
def transform(
|
|
157
|
-
self,
|
|
159
|
+
self,
|
|
160
|
+
response: list[ResponsePrimitive],
|
|
158
161
|
) -> tuple[str, int] | None:
|
|
159
162
|
return nativestr(response[0]), int(response[1]) if response else None
|
|
160
163
|
|
|
@@ -167,6 +170,7 @@ class SentinelInfoCallback(
|
|
|
167
170
|
]
|
|
168
171
|
):
|
|
169
172
|
def transform(
|
|
170
|
-
self,
|
|
173
|
+
self,
|
|
174
|
+
response: list[ResponseType],
|
|
171
175
|
) -> dict[AnyStr, dict[int, dict[str, ResponseType]]]:
|
|
172
176
|
return {response[0]: {r[0]: InfoCallback()(r[1]) for r in response[1]}}
|
|
@@ -10,15 +10,18 @@ from coredis.response.types import ClientInfo, RoleInfo, SlowLogInfo
|
|
|
10
10
|
from coredis.typing import (
|
|
11
11
|
AnyStr,
|
|
12
12
|
ClassVar,
|
|
13
|
+
RedisValueT,
|
|
13
14
|
ResponsePrimitive,
|
|
14
15
|
ResponseType,
|
|
15
16
|
StringT,
|
|
16
|
-
ValueT,
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class TimeCallback(ResponseCallback[list[AnyStr], list[AnyStr], datetime.datetime]):
|
|
21
|
-
def transform(
|
|
21
|
+
def transform(
|
|
22
|
+
self,
|
|
23
|
+
response: list[AnyStr],
|
|
24
|
+
) -> datetime.datetime:
|
|
22
25
|
return datetime.datetime.fromtimestamp(int(response[0])) + datetime.timedelta(
|
|
23
26
|
microseconds=int(response[1]) / 1000.0
|
|
24
27
|
)
|
|
@@ -26,7 +29,8 @@ class TimeCallback(ResponseCallback[list[AnyStr], list[AnyStr], datetime.datetim
|
|
|
26
29
|
|
|
27
30
|
class SlowlogCallback(ResponseCallback[ResponseType, ResponseType, tuple[SlowLogInfo, ...]]):
|
|
28
31
|
def transform(
|
|
29
|
-
self,
|
|
32
|
+
self,
|
|
33
|
+
response: ResponseType,
|
|
30
34
|
) -> tuple[SlowLogInfo, ...]:
|
|
31
35
|
return tuple(
|
|
32
36
|
SlowLogInfo(
|
|
@@ -61,7 +65,10 @@ class ClientInfoCallback(ResponseCallback[ResponseType, ResponseType, ClientInfo
|
|
|
61
65
|
"redir",
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
def transform(
|
|
68
|
+
def transform(
|
|
69
|
+
self,
|
|
70
|
+
response: ResponseType,
|
|
71
|
+
) -> ClientInfo:
|
|
65
72
|
decoded_response = nativestr(response)
|
|
66
73
|
pairs = [pair.split("=", 1) for pair in decoded_response.strip().split(" ")]
|
|
67
74
|
|
|
@@ -75,14 +82,20 @@ class ClientInfoCallback(ResponseCallback[ResponseType, ResponseType, ClientInfo
|
|
|
75
82
|
|
|
76
83
|
|
|
77
84
|
class ClientListCallback(ResponseCallback[ResponseType, ResponseType, tuple[ClientInfo, ...]]):
|
|
78
|
-
def transform(
|
|
85
|
+
def transform(
|
|
86
|
+
self,
|
|
87
|
+
response: ResponseType,
|
|
88
|
+
) -> tuple[ClientInfo, ...]:
|
|
79
89
|
return tuple(ClientInfoCallback()(c) for c in response.splitlines())
|
|
80
90
|
|
|
81
91
|
|
|
82
92
|
class DebugCallback(ResponseCallback[ResponseType, ResponseType, dict[str, str | int]]):
|
|
83
93
|
INT_FIELDS: ClassVar = {"refcount", "serializedlength", "lru", "lru_seconds_idle"}
|
|
84
94
|
|
|
85
|
-
def transform(
|
|
95
|
+
def transform(
|
|
96
|
+
self,
|
|
97
|
+
response: ResponseType,
|
|
98
|
+
) -> dict[str, str | int]:
|
|
86
99
|
# The 'type' of the object is the first item in the response, but isn't
|
|
87
100
|
# prefixed with a name
|
|
88
101
|
|
|
@@ -108,7 +121,10 @@ class InfoCallback(
|
|
|
108
121
|
dict[str, ResponseType],
|
|
109
122
|
]
|
|
110
123
|
):
|
|
111
|
-
def transform(
|
|
124
|
+
def transform(
|
|
125
|
+
self,
|
|
126
|
+
response: StringT,
|
|
127
|
+
) -> dict[str, ResponseType]:
|
|
112
128
|
"""Parses the result of Redis's INFO command into a Python dict"""
|
|
113
129
|
|
|
114
130
|
info: dict[str, Any] = {}
|
|
@@ -149,14 +165,14 @@ class InfoCallback(
|
|
|
149
165
|
cur_info.setdefault("__raw__", []).append(line)
|
|
150
166
|
elif line:
|
|
151
167
|
if cur_info and header:
|
|
152
|
-
if options.get("nested"):
|
|
168
|
+
if self.options.get("nested"):
|
|
153
169
|
info[header] = cur_info
|
|
154
170
|
else:
|
|
155
171
|
info.update(cur_info)
|
|
156
172
|
cur_info = {}
|
|
157
173
|
header = line.lstrip("#").strip().lower()
|
|
158
174
|
if header and header not in info:
|
|
159
|
-
if options.get("nested"):
|
|
175
|
+
if self.options.get("nested"):
|
|
160
176
|
info[header] = cur_info
|
|
161
177
|
else:
|
|
162
178
|
info.update(cur_info)
|
|
@@ -164,7 +180,10 @@ class InfoCallback(
|
|
|
164
180
|
|
|
165
181
|
|
|
166
182
|
class RoleCallback(ResponseCallback[ResponseType, ResponseType, RoleInfo]):
|
|
167
|
-
def transform(
|
|
183
|
+
def transform(
|
|
184
|
+
self,
|
|
185
|
+
response: ResponseType,
|
|
186
|
+
) -> RoleInfo:
|
|
168
187
|
role = nativestr(response[0])
|
|
169
188
|
|
|
170
189
|
def _parse_master(response: Any) -> Any:
|
|
@@ -198,15 +217,17 @@ class RoleCallback(ResponseCallback[ResponseType, ResponseType, RoleInfo]):
|
|
|
198
217
|
|
|
199
218
|
|
|
200
219
|
class LatencyHistogramCallback(
|
|
201
|
-
ResponseCallback[ResponseType, ResponseType, dict[AnyStr, dict[AnyStr,
|
|
220
|
+
ResponseCallback[ResponseType, ResponseType, dict[AnyStr, dict[AnyStr, RedisValueT]]]
|
|
202
221
|
):
|
|
203
222
|
def transform(
|
|
204
|
-
self,
|
|
205
|
-
|
|
223
|
+
self,
|
|
224
|
+
response: ResponseType,
|
|
225
|
+
) -> dict[AnyStr, dict[AnyStr, RedisValueT]]:
|
|
206
226
|
histogram = flat_pairs_to_dict(response)
|
|
207
227
|
for key, value in histogram.items():
|
|
208
228
|
histogram[key] = EncodingInsensitiveDict(flat_pairs_to_dict(value))
|
|
209
229
|
histogram[key]["histogram_usec"] = flat_pairs_to_dict(histogram[key]["histogram_usec"])
|
|
230
|
+
histogram[key] = dict(histogram[key])
|
|
210
231
|
return histogram
|
|
211
232
|
|
|
212
233
|
|
|
@@ -214,6 +235,7 @@ class LatencyCallback(
|
|
|
214
235
|
ResponseCallback[ResponseType, ResponseType, dict[AnyStr, tuple[int, int, int]]]
|
|
215
236
|
):
|
|
216
237
|
def transform(
|
|
217
|
-
self,
|
|
238
|
+
self,
|
|
239
|
+
response: ResponseType,
|
|
218
240
|
) -> dict[AnyStr, tuple[int, int, int]]:
|
|
219
241
|
return {k[0]: (k[1], k[2], k[3]) for k in response}
|
|
@@ -8,7 +8,6 @@ from coredis.typing import (
|
|
|
8
8
|
Iterable,
|
|
9
9
|
ResponsePrimitive,
|
|
10
10
|
ResponseType,
|
|
11
|
-
ValueT,
|
|
12
11
|
)
|
|
13
12
|
|
|
14
13
|
|
|
@@ -16,7 +15,8 @@ class SScanCallback(
|
|
|
16
15
|
ResponseCallback[list[ResponseType], list[ResponseType], tuple[int, set[AnyStr]]]
|
|
17
16
|
):
|
|
18
17
|
def transform(
|
|
19
|
-
self,
|
|
18
|
+
self,
|
|
19
|
+
response: list[ResponseType],
|
|
20
20
|
) -> tuple[int, set[AnyStr]]:
|
|
21
21
|
cursor, r = response
|
|
22
22
|
assert isinstance(cursor, (bytes, str)) and isinstance(r, Iterable)
|
|
@@ -33,9 +33,8 @@ class ItemOrSetCallback(
|
|
|
33
33
|
def transform(
|
|
34
34
|
self,
|
|
35
35
|
response: AnyStr | list[ResponsePrimitive] | set[ResponsePrimitive],
|
|
36
|
-
**options: ValueT | None,
|
|
37
36
|
) -> AnyStr | set[AnyStr]:
|
|
38
|
-
if options.get("count"):
|
|
37
|
+
if self.options.get("count"):
|
|
39
38
|
if isinstance(response, set):
|
|
40
39
|
return cast(set[AnyStr], response)
|
|
41
40
|
if isinstance(response, list):
|