coredis 5.5.0__cp314-cp314-macosx_10_13_x86_64.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.
Files changed (100) hide show
  1. 22fe76227e35f92ab5c3__mypyc.cpython-314-darwin.so +0 -0
  2. coredis/__init__.py +42 -0
  3. coredis/_enum.py +42 -0
  4. coredis/_json.py +11 -0
  5. coredis/_packer.cpython-314-darwin.so +0 -0
  6. coredis/_packer.py +71 -0
  7. coredis/_protocols.py +50 -0
  8. coredis/_py_311_typing.py +20 -0
  9. coredis/_py_312_typing.py +17 -0
  10. coredis/_sidecar.py +114 -0
  11. coredis/_utils.cpython-314-darwin.so +0 -0
  12. coredis/_utils.py +440 -0
  13. coredis/_version.py +34 -0
  14. coredis/_version.pyi +1 -0
  15. coredis/cache.py +801 -0
  16. coredis/client/__init__.py +6 -0
  17. coredis/client/basic.py +1240 -0
  18. coredis/client/cluster.py +1265 -0
  19. coredis/commands/__init__.py +64 -0
  20. coredis/commands/_key_spec.py +517 -0
  21. coredis/commands/_utils.py +108 -0
  22. coredis/commands/_validators.py +159 -0
  23. coredis/commands/_wrappers.py +175 -0
  24. coredis/commands/bitfield.py +110 -0
  25. coredis/commands/constants.py +662 -0
  26. coredis/commands/core.py +8484 -0
  27. coredis/commands/function.py +408 -0
  28. coredis/commands/monitor.py +168 -0
  29. coredis/commands/pubsub.py +905 -0
  30. coredis/commands/request.py +108 -0
  31. coredis/commands/script.py +296 -0
  32. coredis/commands/sentinel.py +246 -0
  33. coredis/config.py +50 -0
  34. coredis/connection.py +906 -0
  35. coredis/constants.cpython-314-darwin.so +0 -0
  36. coredis/constants.py +37 -0
  37. coredis/credentials.py +45 -0
  38. coredis/exceptions.py +360 -0
  39. coredis/experimental/__init__.py +1 -0
  40. coredis/globals.py +23 -0
  41. coredis/modules/__init__.py +121 -0
  42. coredis/modules/autocomplete.py +138 -0
  43. coredis/modules/base.py +262 -0
  44. coredis/modules/filters.py +1319 -0
  45. coredis/modules/graph.py +362 -0
  46. coredis/modules/json.py +691 -0
  47. coredis/modules/response/__init__.py +0 -0
  48. coredis/modules/response/_callbacks/__init__.py +0 -0
  49. coredis/modules/response/_callbacks/autocomplete.py +42 -0
  50. coredis/modules/response/_callbacks/graph.py +237 -0
  51. coredis/modules/response/_callbacks/json.py +21 -0
  52. coredis/modules/response/_callbacks/search.py +221 -0
  53. coredis/modules/response/_callbacks/timeseries.py +158 -0
  54. coredis/modules/response/types.py +179 -0
  55. coredis/modules/search.py +1089 -0
  56. coredis/modules/timeseries.py +1139 -0
  57. coredis/parser.cpython-314-darwin.so +0 -0
  58. coredis/parser.py +344 -0
  59. coredis/pipeline.py +1225 -0
  60. coredis/pool/__init__.py +11 -0
  61. coredis/pool/basic.py +453 -0
  62. coredis/pool/cluster.py +517 -0
  63. coredis/pool/nodemanager.py +340 -0
  64. coredis/py.typed +0 -0
  65. coredis/recipes/__init__.py +0 -0
  66. coredis/recipes/credentials/__init__.py +5 -0
  67. coredis/recipes/credentials/iam_provider.py +63 -0
  68. coredis/recipes/locks/__init__.py +5 -0
  69. coredis/recipes/locks/extend.lua +17 -0
  70. coredis/recipes/locks/lua_lock.py +281 -0
  71. coredis/recipes/locks/release.lua +10 -0
  72. coredis/response/__init__.py +5 -0
  73. coredis/response/_callbacks/__init__.py +538 -0
  74. coredis/response/_callbacks/acl.py +32 -0
  75. coredis/response/_callbacks/cluster.py +183 -0
  76. coredis/response/_callbacks/command.py +86 -0
  77. coredis/response/_callbacks/connection.py +31 -0
  78. coredis/response/_callbacks/geo.py +58 -0
  79. coredis/response/_callbacks/hash.py +85 -0
  80. coredis/response/_callbacks/keys.py +59 -0
  81. coredis/response/_callbacks/module.py +33 -0
  82. coredis/response/_callbacks/script.py +85 -0
  83. coredis/response/_callbacks/sentinel.py +179 -0
  84. coredis/response/_callbacks/server.py +241 -0
  85. coredis/response/_callbacks/sets.py +44 -0
  86. coredis/response/_callbacks/sorted_set.py +204 -0
  87. coredis/response/_callbacks/streams.py +185 -0
  88. coredis/response/_callbacks/strings.py +70 -0
  89. coredis/response/_callbacks/vector_sets.py +159 -0
  90. coredis/response/_utils.py +33 -0
  91. coredis/response/types.py +416 -0
  92. coredis/retry.py +233 -0
  93. coredis/sentinel.py +477 -0
  94. coredis/stream.py +369 -0
  95. coredis/tokens.py +2286 -0
  96. coredis/typing.py +593 -0
  97. coredis-5.5.0.dist-info/METADATA +211 -0
  98. coredis-5.5.0.dist-info/RECORD +100 -0
  99. coredis-5.5.0.dist-info/WHEEL +6 -0
  100. coredis-5.5.0.dist-info/licenses/LICENSE +23 -0
Binary file
coredis/constants.py ADDED
@@ -0,0 +1,37 @@
1
+ from __future__ import annotations
2
+
3
+ from coredis._utils import b
4
+ from coredis.typing import Final
5
+
6
+ SYM_STAR: Final[bytes] = b("*")
7
+ SYM_DOLLAR: Final[bytes] = b("$")
8
+ SYM_CRLF: Final[bytes] = b("\r\n")
9
+ SYM_LF: Final[bytes] = b("\n")
10
+ SYM_EMPTY: Final[bytes] = b("")
11
+
12
+
13
+ class RESPDataType:
14
+ """
15
+ Markers used by redis server to signal
16
+ the type of data being sent.
17
+
18
+ See:
19
+
20
+ - `RESP protocol spec <https://redis.io/docs/reference/protocol-spec/>`__
21
+ - `RESP3 specification <https://github.com/antirez/RESP3/blob/master/spec.md>`__
22
+ """
23
+
24
+ NONE: Final[int] = ord(b"_")
25
+ SIMPLE_STRING: Final[int] = ord(b"+")
26
+ BULK_STRING: Final[int] = ord(b"$")
27
+ VERBATIM: Final[int] = ord(b"=")
28
+ BOOLEAN: Final[int] = ord(b"#")
29
+ INT: Final[int] = ord(b":")
30
+ DOUBLE: Final[int] = ord(b",")
31
+ BIGNUMBER: Final[int] = ord(b"(")
32
+ ARRAY: Final[int] = ord(b"*")
33
+ PUSH: Final[int] = ord(b">")
34
+ MAP: Final[int] = ord(b"%")
35
+ SET: Final[int] = ord(b"~")
36
+ ERROR: Final[int] = ord(b"-")
37
+ ATTRIBUTE: Final[int] = ord(b"|")
coredis/credentials.py ADDED
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC, abstractmethod
4
+
5
+ from coredis.typing import NamedTuple
6
+
7
+
8
+ class UserPass(NamedTuple):
9
+ """
10
+ Username/password tuple.
11
+ """
12
+
13
+ #: Username
14
+ username: str
15
+ #: Password
16
+ password: str
17
+
18
+
19
+ class AbstractCredentialProvider(ABC):
20
+ """
21
+ Abstract credential provider
22
+ """
23
+
24
+ @abstractmethod
25
+ async def get_credentials(self) -> UserPass:
26
+ """
27
+ Returns an instance of :class:`coredis.credentials.UserPass` for
28
+ establishing a connection to the redis server.
29
+ """
30
+ pass
31
+
32
+
33
+ class UserPassCredentialProvider(AbstractCredentialProvider):
34
+ """
35
+ Credential provider that just returns a
36
+ :paramref:`UserPassCredentialProvider.password`
37
+ and/or :paramref:`UserPassCredentialProvider.username`.
38
+ """
39
+
40
+ def __init__(self, username: str | None = None, password: str | None = None) -> None:
41
+ self.username = username or ""
42
+ self.password = password or ""
43
+
44
+ async def get_credentials(self) -> UserPass:
45
+ return UserPass(self.username or "default", self.password)
coredis/exceptions.py ADDED
@@ -0,0 +1,360 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+
5
+ from coredis.typing import RedisValueT
6
+
7
+
8
+ class RedisError(Exception):
9
+ """
10
+ Base exception from which all other exceptions in coredis
11
+ derive from.
12
+ """
13
+
14
+
15
+ class CommandSyntaxError(RedisError):
16
+ """
17
+ Raised when a redis command is called with an invalid syntax
18
+ """
19
+
20
+ def __init__(self, arguments: set[str], message: str) -> None:
21
+ self.arguments: set[str] = arguments
22
+ super().__init__(message)
23
+
24
+
25
+ class CommandNotSupportedError(RedisError):
26
+ """
27
+ Raised when the target server doesn't support a command due to
28
+ version mismatch
29
+ """
30
+
31
+ def __init__(self, cmd: str, current_version: str) -> None:
32
+ super().__init__(f"{cmd} is not supported on server version {current_version}")
33
+
34
+
35
+ class ModuleCommandNotSupportedError(CommandNotSupportedError):
36
+ """
37
+ Raised when the target server doesn't support a module command due to
38
+ version mismatch of the module
39
+ """
40
+
41
+ def __init__(self, cmd: str, module: str, current_version: str) -> None:
42
+ RedisError.__init__(
43
+ self,
44
+ (
45
+ f"{cmd} is not supported on {module} version {current_version}"
46
+ if current_version
47
+ else f"{cmd} is not supported since Module: {module} is not available"
48
+ ),
49
+ )
50
+
51
+
52
+ class ConnectionError(RedisError):
53
+ pass
54
+
55
+
56
+ class ProtocolError(ConnectionError):
57
+ """
58
+ Raised on errors related to ser/deser protocol parsing
59
+ """
60
+
61
+
62
+ class TimeoutError(RedisError):
63
+ pass
64
+
65
+
66
+ class BusyLoadingError(ConnectionError):
67
+ pass
68
+
69
+
70
+ class InvalidResponse(RedisError):
71
+ pass
72
+
73
+
74
+ class ResponseError(RedisError):
75
+ pass
76
+
77
+
78
+ class DataError(RedisError):
79
+ pass
80
+
81
+
82
+ class NoKeyError(RedisError):
83
+ """
84
+ Raised when a key provided in the command is missing
85
+ """
86
+
87
+
88
+ class ReplicationError(RedisError):
89
+ """
90
+ Raised when the replication requirements were not met
91
+ """
92
+
93
+ def __init__(self, command: bytes, replicas: int, timeout: int):
94
+ super().__init__(
95
+ f"Command {str(command)} did not replicate to {replicas} replicas within {timeout} ms."
96
+ )
97
+
98
+
99
+ class PersistenceError(RedisError):
100
+ """
101
+ Raised when the persistence requirements were not met
102
+ """
103
+
104
+ def __init__(self, command: bytes, local: int, replicas: int, timeout: int):
105
+ super().__init__(
106
+ f"Command {str(command)} did not sync to the aof of {local} hosts and/or {replicas} "
107
+ f"replicas within {timeout} ms."
108
+ )
109
+
110
+
111
+ class NotBusyError(ResponseError):
112
+ """
113
+ Raised when script kill or function kill have nothing to terminate
114
+ """
115
+
116
+
117
+ class UnblockedError(ResponseError):
118
+ """
119
+ Raised if a blocked client is unblocked forcefully
120
+ """
121
+
122
+
123
+ class WrongTypeError(ResponseError):
124
+ """
125
+ Raised when an operation is performed on a key
126
+ containing a datatype that doesn't support the operation
127
+ """
128
+
129
+
130
+ class PubSubError(RedisError):
131
+ pass
132
+
133
+
134
+ class WatchError(RedisError):
135
+ pass
136
+
137
+
138
+ class NoScriptError(ResponseError):
139
+ pass
140
+
141
+
142
+ class ExecAbortError(ResponseError):
143
+ pass
144
+
145
+
146
+ class ReadOnlyError(ResponseError):
147
+ pass
148
+
149
+
150
+ class LockError(RedisError, ValueError):
151
+ """Errors acquiring or releasing a lock"""
152
+
153
+ # NOTE: For backwards compatability, this class derives from ValueError.
154
+ # This was originally chosen to behave like threading.Lock.
155
+
156
+
157
+ class LockAcquisitionError(LockError):
158
+ """Errors acquiring a lock"""
159
+
160
+
161
+ class LockReleaseError(LockError):
162
+ """Errors releasing a lock"""
163
+
164
+
165
+ class LockExtensionError(LockError):
166
+ """Errors extending a lock"""
167
+
168
+
169
+ class RedisClusterException(Exception):
170
+ """Base exception for the RedisCluster client"""
171
+
172
+
173
+ class ClusterError(RedisError):
174
+ """
175
+ Cluster errors occurred multiple times, resulting in an exhaustion of the
176
+ command execution ``TTL``
177
+ """
178
+
179
+
180
+ class ClusterCrossSlotError(ResponseError):
181
+ """Raised when keys in request don't hash to the same slot"""
182
+
183
+ def __init__(
184
+ self,
185
+ message: str | None = None,
186
+ command: bytes | None = None,
187
+ keys: tuple[RedisValueT, ...] | None = None,
188
+ ) -> None:
189
+ super().__init__(message or "Keys in request don't hash to the same slot")
190
+ self.command = command
191
+ self.keys = keys
192
+
193
+
194
+ class ClusterRoutingError(RedisClusterException):
195
+ """Raised when keys in request can't be routed to destination nodes"""
196
+
197
+
198
+ class ClusterDownError(ClusterError, ResponseError):
199
+ """
200
+ Error indicated ``CLUSTERDOWN`` error received from cluster.
201
+
202
+ By default Redis Cluster nodes stop accepting queries if they detect there
203
+ is at least a hash slot uncovered (no available node is serving it).
204
+ This way if the cluster is partially down (for example a range of hash
205
+ slots are no longer covered) the entire cluster eventually becomes
206
+ unavailable. It automatically returns available as soon as all the slots
207
+ are covered again.
208
+ """
209
+
210
+ def __init__(self, resp: str) -> None:
211
+ self.args = (resp,)
212
+ self.message = resp
213
+
214
+
215
+ class ClusterTransactionError(ClusterError):
216
+ def __init__(self, msg: str) -> None:
217
+ self.msg = msg
218
+
219
+
220
+ class ClusterResponseError(ClusterError):
221
+ """
222
+ Raised when application logic to combine multi node
223
+ cluster responses has errors.
224
+ """
225
+
226
+
227
+ class AskError(ResponseError):
228
+ """
229
+ Error indicated ``ASK`` error received from cluster.
230
+
231
+ When a slot is set as ``MIGRATING``, the node will accept all queries that
232
+ pertain to this hash slot, but only if the key in question exists,
233
+ otherwise the query is forwarded using a -ASK redirection to the node that
234
+ is target of the migration.
235
+
236
+ src node: ``MIGRATING`` to dst node
237
+ get > ``ASK`` error
238
+ ask dst node > ``ASKING`` command
239
+ dst node: ``IMPORTING`` from src node
240
+ asking command only affects next command
241
+ any op will be allowed after asking command
242
+ """
243
+
244
+ def __init__(self, resp: str) -> None:
245
+ self.args = (resp,)
246
+ self.message = resp
247
+ slot_id, new_node = resp.split(" ")
248
+ host, port = new_node.rsplit(":", 1)
249
+ self.slot_id = int(slot_id)
250
+ self.node_addr = self.host, self.port = host, int(port)
251
+
252
+
253
+ class TryAgainError(ResponseError):
254
+ """
255
+ Error indicated ``TRYAGAIN`` error received from cluster.
256
+ Operations on keys that don't exist or are - during resharding - split
257
+ between the source and destination nodes, will generate a -``TRYAGAIN`` error.
258
+ """
259
+
260
+
261
+ class MovedError(AskError):
262
+ """
263
+ Error indicated ``MOVED`` error received from cluster.
264
+ A request sent to a node that doesn't serve this key will be replayed with
265
+ a ``MOVED`` error that points to the correct node.
266
+ """
267
+
268
+
269
+ class AuthenticationError(ResponseError):
270
+ """
271
+ Base class for authentication errors
272
+ """
273
+
274
+
275
+ class AuthenticationFailureError(AuthenticationError):
276
+ """
277
+ Raised when authentication parameters were provided
278
+ but were invalid
279
+ """
280
+
281
+
282
+ class AuthenticationRequiredError(AuthenticationError):
283
+ """
284
+ Raised when authentication parameters are required
285
+ but not provided
286
+ """
287
+
288
+
289
+ class AuthorizationError(ResponseError):
290
+ """
291
+ Base class for authorization errors
292
+ """
293
+
294
+
295
+ class FunctionError(RedisError):
296
+ """
297
+ Raised for errors relating to redis functions
298
+ """
299
+
300
+
301
+ class SentinelError(RedisError):
302
+ pass
303
+
304
+
305
+ class PrimaryNotFoundError(SentinelError):
306
+ """
307
+ Raised when a primary cannot be located in a
308
+ sentinel managed redis
309
+ """
310
+
311
+
312
+ class ReplicaNotFoundError(SentinelError):
313
+ """
314
+ Raised when a replica cannot be located in a
315
+ sentinel managed redis
316
+ """
317
+
318
+
319
+ class UnknownCommandError(ResponseError):
320
+ """
321
+ Raised when the server returns an error response relating
322
+ to an unknown command.
323
+ """
324
+
325
+ ERROR_REGEX = re.compile("unknown command (.*?)")
326
+ #: Name of command requested
327
+ command: str
328
+
329
+ def __init__(self, message: str) -> None:
330
+ command_match = self.ERROR_REGEX.findall(message)
331
+
332
+ if command_match:
333
+ self.command = command_match.pop()
334
+ super().__init__(message)
335
+
336
+
337
+ class StreamConsumerError(RedisError):
338
+ """
339
+ Base exception for stream consumer related errors
340
+ """
341
+
342
+
343
+ class StreamConsumerGroupError(StreamConsumerError):
344
+ """
345
+ Base exception for consumer group related errors
346
+ """
347
+
348
+
349
+ class StreamDuplicateConsumerGroupError(StreamConsumerGroupError):
350
+ """
351
+ Raised when and attempt to create a stream consumer
352
+ group fails because it already exists
353
+ """
354
+
355
+
356
+ class StreamConsumerInitializationError(StreamConsumerError):
357
+ """
358
+ Raised when a stream consumer could not be initialized
359
+ based on the configuration provided
360
+ """
@@ -0,0 +1 @@
1
+ from __future__ import annotations
coredis/globals.py ADDED
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+
3
+ from collections import defaultdict
4
+ from typing import TYPE_CHECKING
5
+
6
+ from coredis.commands.constants import CommandFlag
7
+
8
+ if TYPE_CHECKING:
9
+ from coredis.modules.base import ModuleGroupRegistry, ModuleRegistry
10
+
11
+ #: Populated by the @redis_command wrapper
12
+ READONLY_COMMANDS: set[bytes] = set()
13
+ #: Populated by the @redis_command wrapper
14
+ COMMAND_FLAGS: dict[bytes, set[CommandFlag]] = defaultdict(set)
15
+
16
+ #: Populated by the @redis_command wrapper
17
+ CACHEABLE_COMMANDS: set[bytes] = set()
18
+
19
+ #: Populated by ModuleGroupRegistry
20
+ MODULE_GROUPS: set[ModuleGroupRegistry] = set()
21
+
22
+ #: Populated by ModuleRegistry
23
+ MODULES: dict[str, ModuleRegistry] = {}
@@ -0,0 +1,121 @@
1
+ from __future__ import annotations
2
+
3
+ from deprecated.sphinx import deprecated, versionadded
4
+
5
+ from coredis.commands import CommandMixin
6
+ from coredis.typing import AnyStr
7
+
8
+ from .autocomplete import Autocomplete
9
+ from .filters import (
10
+ BloomFilter,
11
+ CountMinSketch,
12
+ CuckooFilter,
13
+ RedisBloom,
14
+ TDigest,
15
+ TopK,
16
+ )
17
+ from .graph import Graph
18
+ from .json import Json, RedisJSON
19
+ from .search import RediSearch, Search
20
+ from .timeseries import RedisTimeSeries, TimeSeries
21
+
22
+
23
+ class ModuleMixin(CommandMixin[AnyStr]):
24
+ @property
25
+ @versionadded(version="4.12.0")
26
+ def json(self) -> Json[AnyStr]:
27
+ """
28
+ Property to access :class:`~coredis.modules.Json` commands.
29
+ """
30
+ return Json(self)
31
+
32
+ @property
33
+ @versionadded(version="4.12.0")
34
+ def bf(self) -> BloomFilter[AnyStr]:
35
+ """
36
+ Property to access :class:`~coredis.modules.BloomFilter` commands.
37
+ """
38
+ return BloomFilter(self)
39
+
40
+ @property
41
+ @versionadded(version="4.12.0")
42
+ def cf(self) -> CuckooFilter[AnyStr]:
43
+ """
44
+ Property to access :class:`~coredis.modules.CuckooFilter` commands.
45
+ """
46
+ return CuckooFilter(self)
47
+
48
+ @property
49
+ @versionadded(version="4.12.0")
50
+ def cms(self) -> CountMinSketch[AnyStr]:
51
+ """
52
+ Property to access :class:`~coredis.modules.CountMinSketch` commands.
53
+ """
54
+ return CountMinSketch(self)
55
+
56
+ @property
57
+ @versionadded(version="4.12.0")
58
+ def tdigest(self) -> TDigest[AnyStr]:
59
+ """
60
+ Property to access :class:`~coredis.modules.TDigest` commands.
61
+ """
62
+ return TDigest(self)
63
+
64
+ @property
65
+ @versionadded(version="4.12.0")
66
+ def topk(self) -> TopK[AnyStr]:
67
+ """
68
+ Property to access :class:`~coredis.modules.TopK` commands.
69
+ """
70
+ return TopK(self)
71
+
72
+ @property
73
+ @versionadded(version="4.12.0")
74
+ def timeseries(self) -> TimeSeries[AnyStr]:
75
+ """
76
+ Property to access :class:`~coredis.modules.TimeSeries` commands.
77
+ """
78
+ return TimeSeries(self)
79
+
80
+ @property
81
+ @versionadded(version="4.12.0")
82
+ def search(self) -> Search[AnyStr]:
83
+ """
84
+ Property to access :class:`~coredis.modules.Search` commands.
85
+ """
86
+ return Search(self)
87
+
88
+ @property
89
+ @versionadded(version="4.12.0")
90
+ def autocomplete(self) -> Autocomplete[AnyStr]:
91
+ """
92
+ Property to access :class:`~coredis.modules.Autocomplete` commands.
93
+ """
94
+ return Autocomplete(self)
95
+
96
+ @property
97
+ @versionadded(version="4.12.0")
98
+ @deprecated(
99
+ "RedisGraph has been discontinued and support for it's commands will be removed in 6.0",
100
+ version="5.2.1",
101
+ )
102
+ def graph(self) -> Graph[AnyStr]:
103
+ """
104
+ Property to access :class:`~coredis.modules.Graph` commands.
105
+ """
106
+ return Graph(self)
107
+
108
+
109
+ __all__ = [
110
+ "RediSearch",
111
+ "RedisBloom",
112
+ "RedisJSON",
113
+ "RedisTimeSeries",
114
+ "Json",
115
+ "BloomFilter",
116
+ "CuckooFilter",
117
+ "CountMinSketch",
118
+ "TopK",
119
+ "TDigest",
120
+ "TimeSeries",
121
+ ]