coredis 4.24.0__py3-none-any.whl → 5.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.

Potentially problematic release.


This version of coredis might be problematic. Click here for more details.

Files changed (78) hide show
  1. coredis/__init__.py +1 -3
  2. coredis/_packer.py +10 -10
  3. coredis/_protocols.py +19 -51
  4. coredis/_py_311_typing.py +20 -0
  5. coredis/_py_312_typing.py +17 -0
  6. coredis/_utils.py +49 -55
  7. coredis/_version.py +3 -3
  8. coredis/cache.py +57 -82
  9. coredis/client/__init__.py +1 -2
  10. coredis/client/basic.py +129 -56
  11. coredis/client/cluster.py +147 -70
  12. coredis/commands/__init__.py +27 -7
  13. coredis/commands/_key_spec.py +11 -10
  14. coredis/commands/_utils.py +1 -1
  15. coredis/commands/_validators.py +30 -20
  16. coredis/commands/_wrappers.py +19 -99
  17. coredis/commands/bitfield.py +10 -2
  18. coredis/commands/constants.py +20 -3
  19. coredis/commands/core.py +1674 -1251
  20. coredis/commands/function.py +21 -19
  21. coredis/commands/monitor.py +0 -71
  22. coredis/commands/pubsub.py +7 -142
  23. coredis/commands/request.py +108 -0
  24. coredis/commands/script.py +21 -22
  25. coredis/commands/sentinel.py +60 -49
  26. coredis/connection.py +14 -15
  27. coredis/exceptions.py +2 -2
  28. coredis/experimental/__init__.py +0 -4
  29. coredis/globals.py +3 -0
  30. coredis/modules/autocomplete.py +28 -30
  31. coredis/modules/base.py +15 -31
  32. coredis/modules/filters.py +269 -245
  33. coredis/modules/graph.py +61 -62
  34. coredis/modules/json.py +172 -140
  35. coredis/modules/response/_callbacks/autocomplete.py +5 -4
  36. coredis/modules/response/_callbacks/graph.py +34 -29
  37. coredis/modules/response/_callbacks/json.py +5 -3
  38. coredis/modules/response/_callbacks/search.py +49 -53
  39. coredis/modules/response/_callbacks/timeseries.py +18 -30
  40. coredis/modules/response/types.py +1 -5
  41. coredis/modules/search.py +186 -169
  42. coredis/modules/timeseries.py +184 -164
  43. coredis/parser.py +6 -19
  44. coredis/pipeline.py +477 -521
  45. coredis/pool/basic.py +7 -7
  46. coredis/pool/cluster.py +3 -3
  47. coredis/pool/nodemanager.py +10 -3
  48. coredis/response/_callbacks/__init__.py +76 -57
  49. coredis/response/_callbacks/acl.py +0 -3
  50. coredis/response/_callbacks/cluster.py +25 -16
  51. coredis/response/_callbacks/command.py +8 -6
  52. coredis/response/_callbacks/connection.py +4 -3
  53. coredis/response/_callbacks/geo.py +17 -13
  54. coredis/response/_callbacks/hash.py +13 -11
  55. coredis/response/_callbacks/keys.py +9 -5
  56. coredis/response/_callbacks/module.py +2 -3
  57. coredis/response/_callbacks/script.py +6 -8
  58. coredis/response/_callbacks/sentinel.py +21 -17
  59. coredis/response/_callbacks/server.py +36 -14
  60. coredis/response/_callbacks/sets.py +3 -4
  61. coredis/response/_callbacks/sorted_set.py +27 -24
  62. coredis/response/_callbacks/streams.py +22 -13
  63. coredis/response/_callbacks/strings.py +7 -6
  64. coredis/response/_callbacks/vector_sets.py +159 -0
  65. coredis/response/types.py +13 -4
  66. coredis/retry.py +12 -13
  67. coredis/sentinel.py +11 -1
  68. coredis/stream.py +4 -3
  69. coredis/tokens.py +348 -16
  70. coredis/typing.py +432 -81
  71. {coredis-4.24.0.dist-info → coredis-5.0.0.dist-info}/METADATA +4 -9
  72. coredis-5.0.0.dist-info/RECORD +95 -0
  73. coredis/client/keydb.py +0 -336
  74. coredis/pipeline.pyi +0 -2103
  75. coredis-4.24.0.dist-info/RECORD +0 -93
  76. {coredis-4.24.0.dist-info → coredis-5.0.0.dist-info}/WHEEL +0 -0
  77. {coredis-4.24.0.dist-info → coredis-5.0.0.dist-info}/licenses/LICENSE +0 -0
  78. {coredis-4.24.0.dist-info → coredis-5.0.0.dist-info}/top_level.txt +0 -0
coredis/typing.py CHANGED
@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- import warnings
3
+ import dataclasses
4
+ import inspect
5
+ import sys
4
6
  from collections import OrderedDict
5
7
  from collections.abc import (
6
8
  AsyncGenerator,
@@ -20,9 +22,10 @@ from collections.abc import (
20
22
  Set,
21
23
  ValuesView,
22
24
  )
23
- from types import ModuleType
25
+ from types import GenericAlias, ModuleType, UnionType
24
26
  from typing import (
25
27
  TYPE_CHECKING,
28
+ Any,
26
29
  AnyStr,
27
30
  ClassVar,
28
31
  Final,
@@ -34,45 +37,23 @@ from typing import (
34
37
  TypedDict,
35
38
  TypeGuard,
36
39
  TypeVar,
40
+ cast,
41
+ get_origin,
42
+ get_type_hints,
37
43
  runtime_checkable,
38
44
  )
39
45
 
40
- from typing_extensions import Self
46
+ from beartype import beartype
47
+ from beartype.door import infer_hint, is_bearable, is_subhint
48
+ from typing_extensions import (
49
+ NotRequired,
50
+ Self,
51
+ Unpack,
52
+ )
41
53
 
42
54
  from coredis.config import Config
43
55
 
44
- _runtime_checks = False
45
- _beartype_found = False
46
-
47
- try:
48
- import beartype
49
-
50
- if not TYPE_CHECKING:
51
- from beartype.typing import ( # noqa: F811
52
- Iterable,
53
- Iterator,
54
- Mapping,
55
- MutableMapping,
56
- MutableSequence,
57
- MutableSet,
58
- OrderedDict,
59
- Sequence,
60
- ValuesView,
61
- )
62
- _beartype_found = True
63
- except ImportError: # pragma: no cover
64
- pass
65
-
66
- if Config.runtime_checks and not TYPE_CHECKING: # pragma: no cover
67
- if _beartype_found:
68
- _runtime_checks = True
69
- else:
70
- warnings.warn(
71
- "Runtime checks were enabled via environment variable COREDIS_RUNTIME_CHECKS"
72
- " but could not import beartype"
73
- )
74
-
75
- RUNTIME_TYPECHECKS = _runtime_checks
56
+ RUNTIME_TYPECHECKS = Config.runtime_checks and not TYPE_CHECKING
76
57
 
77
58
  P = ParamSpec("P")
78
59
  T_co = TypeVar("T_co", covariant=True)
@@ -80,15 +61,12 @@ R = TypeVar("R")
80
61
 
81
62
 
82
63
  def safe_beartype(func: Callable[P, R]) -> Callable[P, R]:
83
- if TYPE_CHECKING:
84
- return func
85
-
86
- return beartype.beartype(func) if _beartype_found else func
64
+ return beartype(func)
87
65
 
88
66
 
89
67
  def add_runtime_checks(func: Callable[P, R]) -> Callable[P, R]:
90
68
  if RUNTIME_TYPECHECKS and not TYPE_CHECKING:
91
- return safe_beartype(func)
69
+ return beartype(func)
92
70
 
93
71
  return func
94
72
 
@@ -100,9 +78,6 @@ class RedisError(Exception):
100
78
  """
101
79
 
102
80
 
103
- CommandArgList = list[str | bytes | int | float]
104
-
105
-
106
81
  class Node(TypedDict):
107
82
  """
108
83
  Definition of a cluster node
@@ -112,19 +87,414 @@ class Node(TypedDict):
112
87
  port: int
113
88
 
114
89
 
90
+ class RedisCommandP(Protocol):
91
+ """
92
+ Protocol of a redis command with all associated arguments
93
+ converted into the shape expected by the redis server.
94
+ Used by :meth:`~coredis.Redis.execute_command`
95
+ """
96
+
97
+ #: The name of the redis command
98
+ name: bytes
99
+ #: All arguments to be passed to the command
100
+ arguments: tuple[RedisValueT, ...]
101
+
102
+
103
+ @dataclasses.dataclass
104
+ class RedisCommand:
105
+ """
106
+ Convenience data class that conforms to :class:`~coredis.typing.RedisCommandP`
107
+ """
108
+
109
+ #: The name of the redis command
110
+ name: bytes
111
+ #: All arguments to be passed to the command
112
+ arguments: tuple[RedisValueT, ...]
113
+
114
+
115
+ class ExecutionParameters(TypedDict):
116
+ """
117
+ Extra parameters that can be passed to :meth:`~coredis.Redis.execute_command`
118
+ """
119
+
120
+ #: Whether to decode the response
121
+ #: (ignoring the value of :paramref:`~coredis.Redis.decode_responses`)
122
+ decode: NotRequired[bool]
123
+ slot_arguments_range: NotRequired[tuple[int, int]]
124
+
125
+
115
126
  #: Represents the acceptable types of a redis key
116
127
  KeyT = str | bytes
117
128
 
129
+
130
+ class Serializable(Generic[R]):
131
+ """
132
+ Wrapper to be used to pass arbitrary types to redis commands
133
+ to be eventually serialized by :class:`coredis.typing.TypeAdapter.serialize`
134
+
135
+ Wrapping a value in :class:`Serializable` will pass type checking
136
+ wherever a method expects a :class:`coredis.typing.ValueT` - however
137
+ it will still fail if there is no serializer registered through the instance
138
+ of :class:`coredis.typing.TypeAdapter` that is associated with the client.
139
+
140
+ For example::
141
+
142
+ class MyThing:
143
+ ...
144
+
145
+ client = coredis.Redis()
146
+
147
+ # This will pass type checking but will fail with an :exc:`LookupError`
148
+ # at runtime
149
+ await client.set("fubar", coredis.typing.Serializable(MyThing()))
150
+
151
+ # however, if a serializer is registered, the above would succeed
152
+ @client.type_adapter.serializer
153
+ def _(value: MyThing) -> str:
154
+ ... # some way to convert it to a string
155
+ """
156
+
157
+ def __init__(self, value: R) -> None:
158
+ self.value = value
159
+
160
+
161
+ AdaptableType = type | UnionType | GenericAlias
162
+
163
+
164
+ class TypeAdapter:
165
+ """
166
+ Used by the coredis clients :class:`~coredis.Redis` and :class:`~coredis.RedisCluster`
167
+ through :paramref:`~coredis.Redis.type_adapter` for adapting complex types that require
168
+ custom serialization/deserialization with redis commands.
169
+
170
+ For example to use Decimal types with some common redis operations::
171
+
172
+ from decimal import Decimal
173
+ from typing import Any, Mapping, Iterable
174
+ from coredis import Redis
175
+ from coredis.typing import TypeAdapter, Serializable
176
+
177
+ adapter = TypeAdapter()
178
+
179
+ @adapter.serializer
180
+ def decimal_to_str(value: Decimal) -> str:
181
+ return str(value)
182
+
183
+ @adapter.deserializer
184
+ def value_to_decimal(value: str|bytes) -> Decimal:
185
+ return Decimal(value.decode("utf-8") if isinstance(value, bytes) else value)
186
+
187
+ @adapter.deserializer
188
+ def list_to_decimal_list(items: Iterable[str|bytes]) -> list[Decimal]:
189
+ return [value_to_decimal(value) for value in items]
190
+
191
+ @adapter.deserializer
192
+ def mapping_to_decimal_mapping(mapping: Mapping[str|bytes, str|bytes]) -> dict[str|bytes, Decimal]:
193
+ return {key: value_to_decimal(value) for key, value in mapping.items()}
194
+
195
+ client = coredis.Redis(type_adapter=adapter, decode_responses=True)
196
+ await client.set("key", Serializable(Decimal(1.5)))
197
+ await client.lpush("list", [Serializable(Decimal(1.5))])
198
+ await client.hset("dict", {"first": Serializable(Decimal(1.5))})
199
+ assert Decimal(1.5) == await client.get("key").transform(Decimal)
200
+ assert [Decimal(1.5)] == await client.lrange("list", 0, 0).transform(list[Decimal])
201
+ assert {"first": Decimal(1.5)} == await client.hgetall("dict").transform(dict[str, Decimal])
202
+ """
203
+
204
+ def __init__(
205
+ self,
206
+ ) -> None:
207
+ self.__serializers: dict[
208
+ AdaptableType,
209
+ tuple[Callable[[Any], RedisValueT], int],
210
+ ] = {}
211
+ self.__deserializers: dict[
212
+ AdaptableType,
213
+ dict[AdaptableType, tuple[Callable[..., Any], int]],
214
+ ] = {}
215
+ self.__deserializer_cache: dict[
216
+ tuple[AdaptableType, AdaptableType | GenericAlias],
217
+ Callable[..., Any],
218
+ ] = {}
219
+ self.__serializer_cache: dict[AdaptableType, Callable[[Any], RedisValueT]] = {}
220
+
221
+ @classmethod
222
+ def format_type(cls, type_like: AdaptableType) -> str:
223
+ if get_origin(type_like):
224
+ return str(type_like)
225
+ else:
226
+ return getattr(type_like, "__name__", str(type_like))
227
+
228
+ def register(
229
+ self,
230
+ type: type[R] | UnionType,
231
+ serializer: Callable[[R], RedisValueT],
232
+ deserializer: Callable[[Any], R],
233
+ deserializable_type: type = object,
234
+ ) -> None:
235
+ """
236
+ Register both a serializer and a deserializer for :paramref:`type`
237
+
238
+ :param type: The type that should be serialized/deserialized
239
+ :param serializer: a function that receives an instance of :paramref:`type`
240
+ and returns a value of type :data:`coredis.typing.RedisValueT`
241
+ :param deserializer: a function that accepts the return types from
242
+ the redis commands that are expected to be used when deserializing
243
+ to :paramref:`type`.
244
+ :param deserializable_type: the types of values :paramref:`deserializer` should
245
+ be considered for
246
+ """
247
+ self.register_serializer(type, serializer)
248
+ self.register_deserializer(type, deserializer, deserializable_type)
249
+
250
+ def register_serializer(
251
+ self,
252
+ serializable_type: type[R] | UnionType,
253
+ serializer: Callable[[R], RedisValueT],
254
+ ) -> None:
255
+ """
256
+ Register a serializer for :paramref:`type`
257
+
258
+ :param type: The type that will be serialized
259
+ :param serializer: a function that receives an instance of :paramref:`type`
260
+ and returns a value of type :data:`coredis.typing.RedisValueT`
261
+ """
262
+ self.__serializers.setdefault(serializable_type, (serializer, 0))
263
+ self.__serializer_cache.clear()
264
+
265
+ def register_deserializer(
266
+ self,
267
+ deserialized_type: type[R] | UnionType,
268
+ deserializer: Callable[[Any], R],
269
+ deserializable_type: AdaptableType = object,
270
+ ) -> None:
271
+ """
272
+ Register a deserializer for :paramref:`type` and automatically register
273
+ deserializers for common collection types that use this type.
274
+
275
+ :param type: The type that should be deserialized
276
+ :param deserializer: a function that accepts the return types from
277
+ the redis commands that are expected to be used when deserializing
278
+ to :paramref:`type`.
279
+ :param deserializable_type: the types of values :paramref:`deserializer` should
280
+ be considered for
281
+ """
282
+
283
+ def register_collection_deserializer(
284
+ collection_type: AdaptableType,
285
+ deserializable_type: AdaptableType,
286
+ deserializer: Callable[[Any], Any],
287
+ ) -> None:
288
+ self.__deserializers.setdefault(collection_type, {}).setdefault(
289
+ deserializable_type,
290
+ (deserializer, -1),
291
+ )
292
+
293
+ # Register the base deserializer
294
+ self.__deserializers.setdefault(deserialized_type, {})[deserializable_type or object] = (
295
+ deserializer,
296
+ 0,
297
+ )
298
+
299
+ # Register collection deserializers
300
+ register_collection_deserializer(
301
+ GenericAlias(list, (deserialized_type,)),
302
+ GenericAlias(Iterable, deserializable_type),
303
+ lambda v: [deserializer(item) for item in v],
304
+ )
305
+ register_collection_deserializer(
306
+ GenericAlias(set, (deserialized_type,)),
307
+ GenericAlias(Iterable, deserializable_type),
308
+ lambda v: {deserializer(item) for item in v},
309
+ )
310
+ register_collection_deserializer(
311
+ GenericAlias(tuple, (deserialized_type, ...)),
312
+ GenericAlias(Iterable, deserializable_type),
313
+ lambda v: tuple([deserializer(item) for item in v]),
314
+ )
315
+
316
+ # Register dictionary deserializers for existing types
317
+ for t in list(self.__deserializers):
318
+ if t != deserialized_type:
319
+ for rt in list(self.__deserializers[t]):
320
+ _deserializer, priority = self.__deserializers[t][rt]
321
+ if priority >= 0:
322
+ register_collection_deserializer(
323
+ GenericAlias(dict, (t, deserialized_type)),
324
+ GenericAlias(Mapping, (rt, deserializable_type)),
325
+ lambda m, key_deserializer=_deserializer: { # type: ignore
326
+ key_deserializer(k): deserializer(v) for k, v in m.items()
327
+ },
328
+ )
329
+ register_collection_deserializer(
330
+ GenericAlias(dict, (deserialized_type, t)),
331
+ GenericAlias(Mapping, (deserializable_type, rt)),
332
+ lambda m, value_deserializer=_deserializer: { # type: ignore
333
+ deserializer(k): value_deserializer(v) for k, v in m.items()
334
+ },
335
+ )
336
+
337
+ # Register dictionary deserializers for primitive types
338
+ for t in {bytes, str}:
339
+ register_collection_deserializer(
340
+ GenericAlias(dict, (t, deserialized_type)),
341
+ GenericAlias(Mapping, (t, deserializable_type)),
342
+ lambda v: {k: deserializer(v) for k, v in v.items()},
343
+ )
344
+ register_collection_deserializer(
345
+ GenericAlias(dict, (deserialized_type, t)),
346
+ GenericAlias(Mapping, (deserializable_type, t)),
347
+ lambda v: {deserializer(k): v for k, v in v.items()},
348
+ )
349
+
350
+ self.__deserializer_cache.clear()
351
+
352
+ def serializer(self, func: Callable[[R], RedisValueT]) -> Callable[[R], RedisValueT]:
353
+ """
354
+ Decorator for registering a serializer
355
+
356
+ :param func: A serialization function that accepts an instance of
357
+ type `R` and returns one of the types defined by :data:`coredis.typing.RedisValueT`
358
+ The acceptable serializable types are inferred
359
+ from the annotations in the function signature.
360
+
361
+ :raises ValueError: when the appropriate serializable type cannot be
362
+ inferred.
363
+ """
364
+ if (parameters := list(inspect.signature(func).parameters.keys())) and (
365
+ input_hint := get_type_hints(func).get(parameters[0])
366
+ ):
367
+ self.register_serializer(input_hint, func)
368
+ return func
369
+ else:
370
+ raise ValueError(
371
+ "Unable to infer custom input type from decorated function. Check type annotations."
372
+ )
373
+
374
+ def deserializer(self, func: Callable[[Any], R]) -> Callable[[Any], R]:
375
+ """
376
+ Decorator for registering a deserializer
377
+
378
+ :param func: A deserialization function that returns an instance of
379
+ type `R` that can be used with :meth:`deserialize`. The acceptable
380
+ deserializable types and the expected deserialized type are inferred
381
+ from the annotations in the function signature.
382
+
383
+ :raises ValueError: when the appropriate input/output types cannot be
384
+ inferred.
385
+ """
386
+ if (
387
+ (parameters := list(inspect.signature(func).parameters.keys()))
388
+ and (input_hint := get_type_hints(func).get(parameters[0]))
389
+ ) and (response_type := get_type_hints(func).get("return")):
390
+ self.register_deserializer(response_type, func, input_hint)
391
+ return func
392
+ else:
393
+ raise ValueError(
394
+ "Unable to infer response type from decorated function. Check annotations."
395
+ )
396
+
397
+ def serialize(self, value: Serializable[R]) -> RedisValueT:
398
+ """
399
+ Serializes :paramref:`value` into one of the types represented by
400
+ :data:`~coredis.typing.RedisValueT` using a serializer registered
401
+ via :meth:`register_serializer` or decorated by :meth:`serializer`.
402
+
403
+ :param: a value wrapped in :class:`coredis.typing.Serializable`
404
+ """
405
+ value_type = cast(AdaptableType, infer_hint(value.value))
406
+ if not (transform_function := self.__serializer_cache.get(value_type, None)):
407
+ candidate: tuple[AdaptableType, Callable[[R], RedisValueT] | None] = (object, None)
408
+
409
+ for t in self.__serializers:
410
+ if is_bearable(value.value, t):
411
+ if not candidate[1] or is_subhint(t, candidate[0]):
412
+ candidate = (t, self.__serializers[t][0])
413
+ if candidate[1]:
414
+ transform_function = candidate[1]
415
+ self.__serializer_cache[value_type] = transform_function
416
+ if not transform_function:
417
+ raise LookupError(
418
+ f"No registered serializer to serialize {self.format_type(value_type)}"
419
+ )
420
+ return transform_function(value.value)
421
+
422
+ def deserialize(self, value: Any, return_type: type[R]) -> R:
423
+ """
424
+ Deserializes :paramref:`value` into an instance of :paramref:`return_type`
425
+ using a deserializer registered via :meth:`register_deserializer` or decorated
426
+ by :meth:`deserializer`.
427
+
428
+ :param value: the value to be deserialized (typically something returned by one of
429
+ the redis commands)
430
+ :param return_type: The type to deserialize to
431
+ """
432
+ value_type = cast(AdaptableType, infer_hint(value))
433
+ if not (deserializer := self.__deserializer_cache.get((value_type, return_type), None)):
434
+ if exact_match := self.__deserializers.get(return_type, {}).get(value_type, None):
435
+ deserializer = exact_match[0]
436
+ else:
437
+ candidate: tuple[AdaptableType, AdaptableType, Callable[[Any], R] | None, int] = (
438
+ object,
439
+ object,
440
+ None,
441
+ -100,
442
+ )
443
+ for registered_type, transforms in self.__deserializers.items():
444
+ if is_subhint(return_type, registered_type):
445
+ for expected_value_type in transforms:
446
+ if (
447
+ is_bearable(value, expected_value_type)
448
+ and is_subhint(registered_type, candidate[0])
449
+ and is_subhint(expected_value_type, candidate[1])
450
+ and transforms[expected_value_type][1] >= candidate[3]
451
+ ):
452
+ candidate = (
453
+ registered_type,
454
+ expected_value_type,
455
+ transforms[expected_value_type][0],
456
+ transforms[expected_value_type][1],
457
+ )
458
+ deserializer = candidate[2]
459
+ if deserializer:
460
+ deserialized = deserializer(value)
461
+ if RUNTIME_TYPECHECKS and not is_subhint(
462
+ transformed_type := cast(type, infer_hint(deserialized)), return_type
463
+ ):
464
+ raise TypeError(
465
+ f"Invalid deserializer. Requested {self.format_type(return_type)} but deserializer returned {self.format_type(transformed_type)}"
466
+ )
467
+ self.__deserializer_cache[(value_type, return_type)] = deserializer
468
+ return deserialized
469
+ elif is_subhint(value_type, return_type):
470
+ return cast(R, value)
471
+ else:
472
+ raise LookupError(
473
+ f"No registered deserializer to convert {self.format_type(value_type)} to {self.format_type(return_type)}"
474
+ )
475
+
476
+
118
477
  #: Represents the different python primitives that are accepted
119
478
  #: as input parameters for commands that can be used with loosely
120
- #: defined types. These are encoded using the configured encoding
121
- #: before being transmitted.
122
- ValueT = str | bytes | int | float
479
+ #: defined types. These will eventually be serialized before being
480
+ #: sent to redis.
481
+ #:
482
+ #: Additionally any object wrapped in a :class:`Serializable` will be
483
+ #: accepted and will be serialized using an appropriate type adapter
484
+ #: registered with the client. See :ref:`api/typing:custom types` for more details.
485
+ ValueT = str | bytes | int | float | Serializable[Any]
123
486
 
124
487
  #: The canonical type used for input parameters that represent "strings"
125
488
  #: that are transmitted to redis.
126
489
  StringT = str | bytes
127
490
 
491
+ CommandArgList = list[ValueT]
492
+
493
+ #: Primitive types that we can expect to be sent to redis with
494
+ #: simple serialization. The internals of coredis
495
+ #: pass around arguments to redis commands as this type.
496
+ RedisValueT = str | bytes | int | float
497
+
128
498
  #: Restricted union of container types accepted as arguments to apis
129
499
  #: that accept a variable number values for an argument (such as keys, values).
130
500
  #: This is used instead of :class:`typing.Iterable` as the latter allows
@@ -147,45 +517,17 @@ StringT = str | bytes
147
517
  #: length(b"123") # invalid
148
518
  Parameters = list[T_co] | Set[T_co] | tuple[T_co, ...] | ValuesView[T_co] | Iterator[T_co]
149
519
 
150
- #: Mapping of primitives returned by redis
520
+ #: Primitives returned by redis
151
521
  ResponsePrimitive = StringT | int | float | bool | None
152
522
 
153
- #: Represents the total structure of any response for a redis
154
- #: command.
155
- #:
156
- #: This should preferably be represented by a recursive definition to allow for
157
- #: Limitations in runtime type checkers (beartype) requires conditionally loosening
158
- #: the definition with the use of :class:`typing.Any` for now.
159
-
160
- if TYPE_CHECKING:
161
- ResponseType = (
162
- ResponsePrimitive
163
- | list["ResponseType"]
164
- | MutableSet[
165
- ResponsePrimitive | tuple[ResponsePrimitive, ...] | frozenset[ResponsePrimitive]
166
- ]
167
- | dict[
168
- ResponsePrimitive | tuple[ResponsePrimitive, ...] | frozenset[ResponsePrimitive],
169
- "ResponseType",
170
- ]
171
- | RedisError # response errors get mapped to exceptions.
172
- )
523
+ if sys.version_info >= (3, 12):
524
+ from ._py_312_typing import JsonType, ResponseType
173
525
  else:
174
- from typing import Any
175
-
176
- ResponseType = (
177
- ResponsePrimitive
178
- | list[Any]
179
- | MutableSet[
180
- ResponsePrimitive | tuple[ResponsePrimitive, ...] | frozenset[ResponsePrimitive]
181
- ]
182
- | dict[
183
- ResponsePrimitive | tuple[ResponsePrimitive, ...] | frozenset[ResponsePrimitive],
184
- Any,
185
- ]
186
- | RedisError # response errors get mapped to exceptions.
187
- )
526
+ from ._py_311_typing import JsonType, ResponseType
527
+
528
+
188
529
  __all__ = [
530
+ "Serializable",
189
531
  "AnyStr",
190
532
  "AsyncIterator",
191
533
  "AsyncGenerator",
@@ -200,6 +542,7 @@ __all__ = [
200
542
  "Hashable",
201
543
  "Iterable",
202
544
  "Iterator",
545
+ "JsonType",
203
546
  "KeyT",
204
547
  "Literal",
205
548
  "Mapping",
@@ -209,10 +552,14 @@ __all__ = [
209
552
  "MutableSequence",
210
553
  "NamedTuple",
211
554
  "Node",
555
+ "NotRequired",
212
556
  "OrderedDict",
213
557
  "Parameters",
214
558
  "ParamSpec",
215
559
  "Protocol",
560
+ "RedisCommand",
561
+ "RedisCommandP",
562
+ "ExecutionParameters",
216
563
  "ResponsePrimitive",
217
564
  "ResponseType",
218
565
  "runtime_checkable",
@@ -222,8 +569,12 @@ __all__ = [
222
569
  "TypeGuard",
223
570
  "TypedDict",
224
571
  "TypeVar",
572
+ "Unpack",
225
573
  "ValueT",
574
+ "RedisValueT",
226
575
  "ValuesView",
227
576
  "TYPE_CHECKING",
577
+ "TypeAdapter",
578
+ "ValueT",
228
579
  "RUNTIME_TYPECHECKS",
229
580
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: coredis
3
- Version: 4.24.0
3
+ Version: 5.0.0
4
4
  Summary: Python async client for Redis key-value store
5
5
  Home-page: https://github.com/alisaifee/coredis
6
6
  Author: Ali-Akber Saifee
@@ -14,7 +14,6 @@ Project-URL: Documentation, https://coredis.readthedocs.org
14
14
  Keywords: Redis,key-value store,asyncio
15
15
  Classifier: Development Status :: 5 - Production/Stable
16
16
  Classifier: Intended Audience :: Developers
17
- Classifier: License :: OSI Approved :: MIT License
18
17
  Classifier: Operating System :: OS Independent
19
18
  Classifier: Programming Language :: Python
20
19
  Classifier: Programming Language :: Python :: 3.10
@@ -26,11 +25,11 @@ Requires-Python: >=3.10
26
25
  Description-Content-Type: text/markdown
27
26
  License-File: LICENSE
28
27
  Requires-Dist: async_timeout<6,>4
28
+ Requires-Dist: beartype>=0.20
29
29
  Requires-Dist: deprecated>=1.2
30
- Requires-Dist: typing_extensions>=4.3
30
+ Requires-Dist: typing_extensions>=4.13
31
31
  Requires-Dist: packaging<26,>=21
32
32
  Requires-Dist: pympler<2,>1
33
- Requires-Dist: wrapt<2,>=1.1.0
34
33
  Provides-Extra: recipes
35
34
  Requires-Dist: aiobotocore>=2.15.2; extra == "recipes"
36
35
  Requires-Dist: asyncache>=0.3.1; extra == "recipes"
@@ -80,9 +79,6 @@ coredis is an async redis client with support for redis server, cluster & sentin
80
79
  and the [API Documentation](https://coredis.readthedocs.io/en/latest/api/index.html)
81
80
  for more details.
82
81
 
83
- > **Warning**
84
- > The command API does NOT mirror the official python [redis client](https://github.com/redis/redis-py). For details about the high level differences refer to [Divergence from aredis & redis-py](https://coredis.readthedocs.io/en/latest/history.html#divergence-from-aredis-redis-py)
85
-
86
82
  ______________________________________________________________________
87
83
 
88
84
  <!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
@@ -201,7 +197,7 @@ Details about supported Redis modules and their commands can be found
201
197
 
202
198
  ## Compatibility
203
199
 
204
- coredis is tested against redis versions >= `6.4`
200
+ coredis is tested against redis versions >= `7.0`
205
201
  The test matrix status can be reviewed
206
202
  [here](https://github.com/alisaifee/coredis/actions/workflows/main.yml)
207
203
 
@@ -221,7 +217,6 @@ coredis is additionally tested against:
221
217
 
222
218
  **coredis** is known to work with the following databases that have redis protocol compatibility:
223
219
 
224
- - [KeyDB](https://docs.keydb.dev/)
225
220
  - [Dragonfly](https://dragonflydb.io/)
226
221
  - [Redict](https://redict.io/)
227
222
  - [Valkey](https://github.com/valkey-io/valkey)