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.
Files changed (100) hide show
  1. 22fe76227e35f92ab5c3__mypyc.cpython-313-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-313-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-313-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-313-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-313-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
@@ -0,0 +1,138 @@
1
+ from __future__ import annotations
2
+
3
+ from deprecated.sphinx import versionadded
4
+
5
+ from ..commands.constants import CommandFlag, CommandGroup, CommandName
6
+ from ..commands.request import CommandRequest
7
+ from ..response._callbacks import BoolCallback, IntCallback
8
+ from ..tokens import PrefixToken, PureToken
9
+ from ..typing import AnyStr, CommandArgList, KeyT, StringT
10
+ from .base import ModuleGroup, module_command
11
+ from .response._callbacks.autocomplete import AutocompleteCallback
12
+ from .response.types import AutocompleteSuggestion
13
+ from .search import RediSearch
14
+
15
+
16
+ @versionadded(version="4.12")
17
+ class Autocomplete(ModuleGroup[AnyStr]):
18
+ MODULE = RediSearch
19
+ COMMAND_GROUP = CommandGroup.SUGGESTION
20
+
21
+ @module_command(
22
+ CommandName.FT_SUGADD,
23
+ module=MODULE,
24
+ version_introduced="1.0.0",
25
+ group=COMMAND_GROUP,
26
+ )
27
+ def sugadd(
28
+ self,
29
+ key: KeyT,
30
+ string: StringT,
31
+ score: int | float,
32
+ increment_score: bool | None = None,
33
+ payload: StringT | None = None,
34
+ ) -> CommandRequest[int]:
35
+ """
36
+ Adds a suggestion string to an auto-complete suggestion dictionary
37
+
38
+ :param key: The suggestion dictionary key.
39
+ :param string: The suggestion string to index.
40
+ :param score: The floating point number of the suggestion string's weight.
41
+ :param increment_score: Increments the existing entry of the suggestion by
42
+ the given score, instead of replacing the score.
43
+ :param payload: Saves an extra payload with the suggestion, that can be
44
+ fetched when calling :meth:`sugget` by using :paramref:`sugget.withpayloads`
45
+ """
46
+ command_arguments: CommandArgList = [key, string, score]
47
+ if increment_score:
48
+ command_arguments.append(PureToken.INCREMENT)
49
+ if payload:
50
+ command_arguments.extend([PrefixToken.PAYLOAD, payload])
51
+
52
+ return self.client.create_request(
53
+ CommandName.FT_SUGADD, *command_arguments, callback=IntCallback()
54
+ )
55
+
56
+ @module_command(
57
+ CommandName.FT_SUGGET,
58
+ module=MODULE,
59
+ version_introduced="1.0.0",
60
+ group=COMMAND_GROUP,
61
+ cacheable=True,
62
+ flags={CommandFlag.READONLY},
63
+ )
64
+ def sugget(
65
+ self,
66
+ key: KeyT,
67
+ prefix: StringT,
68
+ *,
69
+ fuzzy: bool | None = None,
70
+ withscores: bool | None = None,
71
+ withpayloads: bool | None = None,
72
+ max_suggestions: int | None = None,
73
+ ) -> CommandRequest[tuple[AutocompleteSuggestion[AnyStr], ...] | tuple[()]]:
74
+ """
75
+ Gets completion suggestions for a prefix
76
+
77
+ :param key: The suggestion dictionary key.
78
+ :param prefix: The prefix to complete on.
79
+ :param fuzzy: If ``True``, performs a fuzzy prefix search, including prefixes at
80
+ Levenshtein distance of 1 from the prefix sent.
81
+ :param withscores: If ``True``, also returns the score of each suggestion.
82
+ :param withpayloads: If True, returns optional payloads saved along with the suggestions.
83
+ :param max_suggestions: Limits the results to a maximum of ``max_suggestions``
84
+ """
85
+ command_arguments: CommandArgList = [key, prefix]
86
+ if fuzzy:
87
+ command_arguments.append(PureToken.FUZZY)
88
+ if withscores:
89
+ command_arguments.append(PureToken.WITHSCORES)
90
+ if withpayloads:
91
+ command_arguments.append(PureToken.WITHPAYLOADS)
92
+ if max_suggestions is not None:
93
+ command_arguments.append(PureToken.MAX)
94
+ command_arguments.append(max_suggestions)
95
+
96
+ return self.client.create_request(
97
+ CommandName.FT_SUGGET,
98
+ *command_arguments,
99
+ callback=AutocompleteCallback[AnyStr](withscores=withscores, withpayloads=withpayloads),
100
+ )
101
+
102
+ @module_command(
103
+ CommandName.FT_SUGDEL,
104
+ module=MODULE,
105
+ version_introduced="1.0.0",
106
+ group=COMMAND_GROUP,
107
+ )
108
+ def sugdel(self, key: KeyT, string: StringT) -> CommandRequest[bool]:
109
+ """
110
+ Deletes a string from a suggestion index
111
+
112
+ :param key: The suggestion dictionary key.
113
+ :param string: The suggestion string to index.
114
+
115
+ """
116
+ command_arguments: CommandArgList = [key, string]
117
+
118
+ return self.client.create_request(
119
+ CommandName.FT_SUGDEL, *command_arguments, callback=BoolCallback()
120
+ )
121
+
122
+ @module_command(
123
+ CommandName.FT_SUGLEN,
124
+ module=MODULE,
125
+ version_introduced="1.0.0",
126
+ group=COMMAND_GROUP,
127
+ )
128
+ def suglen(self, key: KeyT) -> CommandRequest[int]:
129
+ """
130
+ Gets the size of an auto-complete suggestion dictionary
131
+
132
+ :param key: The key of the suggestion dictionary.
133
+ """
134
+ command_arguments: CommandArgList = [key]
135
+
136
+ return self.client.create_request(
137
+ CommandName.FT_SUGLEN, *command_arguments, callback=IntCallback()
138
+ )
@@ -0,0 +1,262 @@
1
+ from __future__ import annotations
2
+
3
+ import functools
4
+ import textwrap
5
+ from abc import ABCMeta
6
+ from typing import TYPE_CHECKING, Any, cast
7
+
8
+ from packaging import version
9
+
10
+ from coredis.config import Config
11
+
12
+ from .._protocols import AbstractExecutor
13
+ from ..commands._utils import redis_command_link
14
+ from ..commands._wrappers import (
15
+ ClusterCommandConfig,
16
+ CommandDetails,
17
+ )
18
+ from ..commands.constants import CommandFlag, CommandGroup, CommandName
19
+ from ..commands.request import CommandRequest
20
+ from ..exceptions import CommandSyntaxError, ModuleCommandNotSupportedError
21
+ from ..globals import CACHEABLE_COMMANDS, COMMAND_FLAGS, MODULE_GROUPS, MODULES, READONLY_COMMANDS
22
+ from ..typing import (
23
+ AnyStr,
24
+ Callable,
25
+ ClassVar,
26
+ Generic,
27
+ P,
28
+ R,
29
+ add_runtime_checks,
30
+ )
31
+
32
+ if TYPE_CHECKING:
33
+ import coredis.client
34
+
35
+
36
+ def ensure_compatibility(
37
+ client: coredis.client.Client[Any],
38
+ module: str,
39
+ command_details: CommandDetails,
40
+ kwargs: dict[str, Any],
41
+ ) -> None:
42
+ if (
43
+ Config.optimized
44
+ or not command_details.version_introduced
45
+ or not getattr(client, "verify_version", False)
46
+ or not getattr(client, "server_version", None)
47
+ or getattr(client, "noreply", False)
48
+ ):
49
+ return
50
+ if command_details.version_introduced:
51
+ module_version = client.get_server_module_version(module)
52
+ if module_version and command_details.version_introduced <= module_version:
53
+ if command_details.arguments and set(command_details.arguments.keys()).intersection(
54
+ kwargs.keys()
55
+ ):
56
+ for argument, version_introduced in command_details.arguments.items():
57
+ if version_introduced and version_introduced > module_version:
58
+ raise CommandSyntaxError(
59
+ {argument},
60
+ (
61
+ f"{command_details.command.decode('latin-1')} with `{argument}` "
62
+ f"is not supported in {module} version {module_version}"
63
+ ),
64
+ )
65
+ return
66
+ raise ModuleCommandNotSupportedError(
67
+ command_details.command.decode("latin-1"),
68
+ module,
69
+ str(module_version) if module_version else "",
70
+ )
71
+
72
+
73
+ def module_command(
74
+ command_name: CommandName,
75
+ module: type[Module[Any]],
76
+ group: CommandGroup,
77
+ flags: set[CommandFlag] | None = None,
78
+ cluster: ClusterCommandConfig = ClusterCommandConfig(),
79
+ cacheable: bool | None = None,
80
+ version_introduced: str | None = None,
81
+ version_deprecated: str | None = None,
82
+ arguments: dict[str, dict[str, str]] | None = None,
83
+ ) -> Callable[[Callable[P, CommandRequest[R]]], Callable[P, CommandRequest[R]]]:
84
+ command_details = CommandDetails(
85
+ command_name,
86
+ group,
87
+ version.Version(version_introduced) if version_introduced else None,
88
+ version.Version(version_deprecated) if version_deprecated else None,
89
+ arguments,
90
+ cluster or ClusterCommandConfig(),
91
+ flags or set(),
92
+ None,
93
+ )
94
+
95
+ def wrapper(
96
+ func: Callable[P, CommandRequest[R]],
97
+ ) -> Callable[P, CommandRequest[R]]:
98
+ runtime_checkable = add_runtime_checks(func)
99
+ if flags and CommandFlag.READONLY in flags:
100
+ READONLY_COMMANDS.add(command_name)
101
+ if cacheable:
102
+ CACHEABLE_COMMANDS.add(command_name)
103
+ COMMAND_FLAGS[command_name] = flags or set()
104
+
105
+ @functools.wraps(func)
106
+ def wrapped(*args: P.args, **kwargs: P.kwargs) -> CommandRequest[R]:
107
+ from coredis.client import Redis, RedisCluster
108
+
109
+ mg = cast(ModuleGroup[bytes], args[0])
110
+ client = cast("coredis.client.Client[Any]", mg.client)
111
+ is_regular_client = isinstance(client, (Redis, RedisCluster))
112
+ runtime_checking = not getattr(client, "noreply", None) and is_regular_client
113
+ callable = runtime_checkable if runtime_checking else func
114
+ ensure_compatibility(client, module.NAME, command_details, kwargs)
115
+ return callable(*args, **kwargs)
116
+
117
+ wrapped.__doc__ = textwrap.dedent(wrapped.__doc__ or "")
118
+ if group:
119
+ wrapped.__doc__ = f"""
120
+ {wrapped.__doc__}
121
+
122
+ {module.FULL_NAME} command documentation: {redis_command_link(command_name)}
123
+ """
124
+ if (
125
+ (version_introduced and version_introduced != "1.0.0")
126
+ or version_deprecated
127
+ or command_details.arguments
128
+ ):
129
+ wrapped.__doc__ += """
130
+ Compatibility:
131
+ """
132
+
133
+ if version_introduced and version_introduced != "1.0.0":
134
+ wrapped.__doc__ += f"""
135
+ - New in {module.FULL_NAME} version: `{version_introduced}`
136
+ """
137
+ if version_deprecated:
138
+ wrapped.__doc__ += f"""
139
+ - Deprecated in {module.FULL_NAME} version: `{version_deprecated}`
140
+ """
141
+ if command_details.arguments:
142
+ for argument, min_version in command_details.arguments.items():
143
+ wrapped.__doc__ += f"""
144
+ - :paramref:`{argument}`: New in {module.FULL_NAME} version `{min_version}`
145
+ """
146
+ if cacheable:
147
+ wrapped.__doc__ += """
148
+ .. hint:: Supports client side caching
149
+ """
150
+ setattr(wrapped, "__coredis_command", command_details)
151
+ setattr(wrapped, "__coredis_module", module)
152
+ return wrapped
153
+
154
+ return wrapper
155
+
156
+
157
+ class ModuleRegistry(ABCMeta):
158
+ """
159
+ :meta private:
160
+ """
161
+
162
+ NAME: str
163
+ FULL_NAME: str
164
+ DESCRIPTION: str
165
+ DOCUMENTATION_URL: str
166
+ COMMAND_GROUPS: dict[CommandGroup, type[ModuleGroup[Any]]]
167
+
168
+ def __new__(
169
+ cls, name: str, bases: tuple[type, ...], namespace: dict[str, object]
170
+ ) -> ModuleRegistry:
171
+ if "COMMAND_GROUPS" not in namespace:
172
+ namespace["COMMAND_GROUPS"] = {}
173
+ kls = super().__new__(cls, name, bases, namespace)
174
+ if getattr(kls, "NAME", None):
175
+ MODULES[kls.NAME] = kls
176
+ kls.__doc__ = textwrap.dedent(kls.__doc__ or "")
177
+ kls.__doc__ += f"""
178
+ Type representation of the `{kls.FULL_NAME} <{kls.DOCUMENTATION_URL}>`__ module.
179
+ The class isn't meant to be used directly and exists as a convenient way to capture
180
+ module attributes for documentation & internal use.
181
+ """
182
+ return kls
183
+
184
+
185
+ class ModuleGroupRegistry(ABCMeta):
186
+ """
187
+ :meta private:
188
+ """
189
+
190
+ MODULE: type[Module[Any]]
191
+ COMMAND_GROUP: CommandGroup
192
+
193
+ def __new__(
194
+ cls, name: str, bases: tuple[type, ...], namespace: dict[str, object]
195
+ ) -> ModuleGroupRegistry:
196
+ kls = super().__new__(cls, name, bases, namespace)
197
+ if getattr(kls, "MODULE", None):
198
+ MODULE_GROUPS.add(kls)
199
+ kls.MODULE.COMMAND_GROUPS[kls.COMMAND_GROUP] = cast(type[ModuleGroup[Any]], kls)
200
+ original_doc = textwrap.dedent(kls.__doc__ or "")
201
+ kls.__doc__ = f"""
202
+ Container for the commands in the ``{kls.COMMAND_GROUP.value}`` command group of the
203
+ `{kls.MODULE.FULL_NAME} <{kls.MODULE.DOCUMENTATION_URL}>`__ module.
204
+
205
+ {original_doc}
206
+ """
207
+ return kls
208
+
209
+
210
+ class Module(Generic[AnyStr], metaclass=ModuleRegistry):
211
+ """
212
+ Base class for Redis module implementations.
213
+ This class isn't meant to be used directly by the end
214
+ user, and exists to provide a convenient way to document and group
215
+ redis modules and the command groups that they expose.
216
+ """
217
+
218
+ NAME: ClassVar[str]
219
+ """
220
+ The name of the module as reported by ``MODULES LIST``
221
+ """
222
+ FULL_NAME: ClassVar[str]
223
+ """
224
+ The common name used to refer to the module if it differs from
225
+ the internal name
226
+ """
227
+ DESCRIPTION: ClassVar[str]
228
+ """
229
+ A brief description of what the module does
230
+ """
231
+ DOCUMENTATION_URL: ClassVar[str]
232
+ """
233
+ A link to the module documentation
234
+ """
235
+
236
+ COMMAND_GROUPS: ClassVar[dict[CommandGroup, type[ModuleGroup[Any]]]]
237
+ """
238
+ Mapping of command groups that implement this module. This is auto
239
+ populated by the :class:`ModuleGroupRegistry` metaclass.
240
+ """
241
+
242
+
243
+ class ModuleGroup(Generic[AnyStr], metaclass=ModuleGroupRegistry):
244
+ """
245
+ Base class for Redis module command groups
246
+ """
247
+
248
+ MODULE: ClassVar[type[Module[Any]]]
249
+ """
250
+ The module to which this command group belongs to
251
+
252
+ :meta private:
253
+ """
254
+ COMMAND_GROUP: ClassVar[CommandGroup]
255
+ """
256
+ The command group this class implements
257
+
258
+ :meta private:
259
+ """
260
+
261
+ def __init__(self, client: AbstractExecutor):
262
+ self.client = client