coredis 5.5.0__cp313-cp313-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 22fe76227e35f92ab5c3__mypyc.cpython-313-darwin.so +0 -0
- coredis/__init__.py +42 -0
- coredis/_enum.py +42 -0
- coredis/_json.py +11 -0
- coredis/_packer.cpython-313-darwin.so +0 -0
- coredis/_packer.py +71 -0
- coredis/_protocols.py +50 -0
- coredis/_py_311_typing.py +20 -0
- coredis/_py_312_typing.py +17 -0
- coredis/_sidecar.py +114 -0
- coredis/_utils.cpython-313-darwin.so +0 -0
- coredis/_utils.py +440 -0
- coredis/_version.py +34 -0
- coredis/_version.pyi +1 -0
- coredis/cache.py +801 -0
- coredis/client/__init__.py +6 -0
- coredis/client/basic.py +1240 -0
- coredis/client/cluster.py +1265 -0
- coredis/commands/__init__.py +64 -0
- coredis/commands/_key_spec.py +517 -0
- coredis/commands/_utils.py +108 -0
- coredis/commands/_validators.py +159 -0
- coredis/commands/_wrappers.py +175 -0
- coredis/commands/bitfield.py +110 -0
- coredis/commands/constants.py +662 -0
- coredis/commands/core.py +8484 -0
- coredis/commands/function.py +408 -0
- coredis/commands/monitor.py +168 -0
- coredis/commands/pubsub.py +905 -0
- coredis/commands/request.py +108 -0
- coredis/commands/script.py +296 -0
- coredis/commands/sentinel.py +246 -0
- coredis/config.py +50 -0
- coredis/connection.py +906 -0
- coredis/constants.cpython-313-darwin.so +0 -0
- coredis/constants.py +37 -0
- coredis/credentials.py +45 -0
- coredis/exceptions.py +360 -0
- coredis/experimental/__init__.py +1 -0
- coredis/globals.py +23 -0
- coredis/modules/__init__.py +121 -0
- coredis/modules/autocomplete.py +138 -0
- coredis/modules/base.py +262 -0
- coredis/modules/filters.py +1319 -0
- coredis/modules/graph.py +362 -0
- coredis/modules/json.py +691 -0
- coredis/modules/response/__init__.py +0 -0
- coredis/modules/response/_callbacks/__init__.py +0 -0
- coredis/modules/response/_callbacks/autocomplete.py +42 -0
- coredis/modules/response/_callbacks/graph.py +237 -0
- coredis/modules/response/_callbacks/json.py +21 -0
- coredis/modules/response/_callbacks/search.py +221 -0
- coredis/modules/response/_callbacks/timeseries.py +158 -0
- coredis/modules/response/types.py +179 -0
- coredis/modules/search.py +1089 -0
- coredis/modules/timeseries.py +1139 -0
- coredis/parser.cpython-313-darwin.so +0 -0
- coredis/parser.py +344 -0
- coredis/pipeline.py +1225 -0
- coredis/pool/__init__.py +11 -0
- coredis/pool/basic.py +453 -0
- coredis/pool/cluster.py +517 -0
- coredis/pool/nodemanager.py +340 -0
- coredis/py.typed +0 -0
- coredis/recipes/__init__.py +0 -0
- coredis/recipes/credentials/__init__.py +5 -0
- coredis/recipes/credentials/iam_provider.py +63 -0
- coredis/recipes/locks/__init__.py +5 -0
- coredis/recipes/locks/extend.lua +17 -0
- coredis/recipes/locks/lua_lock.py +281 -0
- coredis/recipes/locks/release.lua +10 -0
- coredis/response/__init__.py +5 -0
- coredis/response/_callbacks/__init__.py +538 -0
- coredis/response/_callbacks/acl.py +32 -0
- coredis/response/_callbacks/cluster.py +183 -0
- coredis/response/_callbacks/command.py +86 -0
- coredis/response/_callbacks/connection.py +31 -0
- coredis/response/_callbacks/geo.py +58 -0
- coredis/response/_callbacks/hash.py +85 -0
- coredis/response/_callbacks/keys.py +59 -0
- coredis/response/_callbacks/module.py +33 -0
- coredis/response/_callbacks/script.py +85 -0
- coredis/response/_callbacks/sentinel.py +179 -0
- coredis/response/_callbacks/server.py +241 -0
- coredis/response/_callbacks/sets.py +44 -0
- coredis/response/_callbacks/sorted_set.py +204 -0
- coredis/response/_callbacks/streams.py +185 -0
- coredis/response/_callbacks/strings.py +70 -0
- coredis/response/_callbacks/vector_sets.py +159 -0
- coredis/response/_utils.py +33 -0
- coredis/response/types.py +416 -0
- coredis/retry.py +233 -0
- coredis/sentinel.py +477 -0
- coredis/stream.py +369 -0
- coredis/tokens.py +2286 -0
- coredis/typing.py +593 -0
- coredis-5.5.0.dist-info/METADATA +211 -0
- coredis-5.5.0.dist-info/RECORD +100 -0
- coredis-5.5.0.dist-info/WHEEL +6 -0
- coredis-5.5.0.dist-info/licenses/LICENSE +23 -0
coredis/modules/json.py
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from deprecated.sphinx import versionadded
|
|
4
|
+
|
|
5
|
+
from .._json import json
|
|
6
|
+
from ..commands.constants import CommandFlag, CommandGroup, CommandName
|
|
7
|
+
from ..commands.request import CommandRequest
|
|
8
|
+
from ..response._callbacks import (
|
|
9
|
+
IntCallback,
|
|
10
|
+
NoopCallback,
|
|
11
|
+
OneOrManyCallback,
|
|
12
|
+
SimpleStringCallback,
|
|
13
|
+
)
|
|
14
|
+
from ..tokens import PureToken
|
|
15
|
+
from ..typing import (
|
|
16
|
+
AnyStr,
|
|
17
|
+
CommandArgList,
|
|
18
|
+
JsonType,
|
|
19
|
+
KeyT,
|
|
20
|
+
Literal,
|
|
21
|
+
Parameters,
|
|
22
|
+
RedisValueT,
|
|
23
|
+
ResponseType,
|
|
24
|
+
StringT,
|
|
25
|
+
)
|
|
26
|
+
from .base import Module, ModuleGroup, module_command
|
|
27
|
+
from .response._callbacks.json import JsonCallback
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class RedisJSON(Module[AnyStr]):
|
|
31
|
+
NAME = "ReJSON"
|
|
32
|
+
FULL_NAME = "RedisJSON"
|
|
33
|
+
DESCRIPTION = """RedisJSON is a Redis module that implements a JSON data type
|
|
34
|
+
and a set of commands to operate on it."""
|
|
35
|
+
DOCUMENTATION_URL = "https://redis.io/docs/stack/json/"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@versionadded(version="4.12")
|
|
39
|
+
class Json(ModuleGroup[AnyStr]):
|
|
40
|
+
MODULE = RedisJSON
|
|
41
|
+
COMMAND_GROUP = CommandGroup.JSON
|
|
42
|
+
|
|
43
|
+
@module_command(
|
|
44
|
+
CommandName.JSON_DEL,
|
|
45
|
+
group=COMMAND_GROUP,
|
|
46
|
+
version_introduced="1.0.0",
|
|
47
|
+
module=MODULE,
|
|
48
|
+
)
|
|
49
|
+
def delete(self, key: KeyT, path: StringT | None = None) -> CommandRequest[int]:
|
|
50
|
+
"""
|
|
51
|
+
Delete a value from a JSON document.
|
|
52
|
+
|
|
53
|
+
:param key: The key of the JSON document.
|
|
54
|
+
:param path: The JSONPath to specify.
|
|
55
|
+
:return: The number of paths deleted
|
|
56
|
+
"""
|
|
57
|
+
command_arguments: CommandArgList = [key]
|
|
58
|
+
if path:
|
|
59
|
+
command_arguments.append(path)
|
|
60
|
+
|
|
61
|
+
return self.client.create_request(
|
|
62
|
+
CommandName.JSON_DEL, *command_arguments, callback=IntCallback()
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
@module_command(
|
|
66
|
+
CommandName.JSON_GET,
|
|
67
|
+
group=COMMAND_GROUP,
|
|
68
|
+
version_introduced="1.0.0",
|
|
69
|
+
module=MODULE,
|
|
70
|
+
cacheable=True,
|
|
71
|
+
flags={CommandFlag.READONLY},
|
|
72
|
+
)
|
|
73
|
+
def get(
|
|
74
|
+
self,
|
|
75
|
+
key: KeyT,
|
|
76
|
+
*paths: StringT,
|
|
77
|
+
) -> CommandRequest[JsonType]:
|
|
78
|
+
"""
|
|
79
|
+
Gets the value at one or more paths
|
|
80
|
+
|
|
81
|
+
:param key: The key of the JSON document.
|
|
82
|
+
:param paths: JSONPath(s) to get values from.
|
|
83
|
+
:return: The value at :paramref:`path`
|
|
84
|
+
"""
|
|
85
|
+
command_arguments: CommandArgList = [key]
|
|
86
|
+
if paths:
|
|
87
|
+
command_arguments.extend(paths)
|
|
88
|
+
|
|
89
|
+
return self.client.create_request(
|
|
90
|
+
CommandName.JSON_GET, *command_arguments, callback=JsonCallback()
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
@module_command(
|
|
94
|
+
CommandName.JSON_FORGET,
|
|
95
|
+
group=COMMAND_GROUP,
|
|
96
|
+
version_introduced="1.0.0",
|
|
97
|
+
module=MODULE,
|
|
98
|
+
)
|
|
99
|
+
def forget(self, key: KeyT, path: RedisValueT | None = None) -> CommandRequest[int]:
|
|
100
|
+
"""
|
|
101
|
+
Deletes an element from a path from a json object
|
|
102
|
+
|
|
103
|
+
:param key: The key of the JSON document.
|
|
104
|
+
:param path: The path(s) to delete from the JSON object.
|
|
105
|
+
|
|
106
|
+
:return: The number of deleted elements.
|
|
107
|
+
"""
|
|
108
|
+
command_arguments: CommandArgList = [key]
|
|
109
|
+
if path:
|
|
110
|
+
command_arguments.append(path)
|
|
111
|
+
return self.client.create_request(
|
|
112
|
+
CommandName.JSON_FORGET, *command_arguments, callback=IntCallback()
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
@module_command(
|
|
116
|
+
CommandName.JSON_TOGGLE,
|
|
117
|
+
group=COMMAND_GROUP,
|
|
118
|
+
version_introduced="2.0.0",
|
|
119
|
+
module=MODULE,
|
|
120
|
+
)
|
|
121
|
+
def toggle(self, key: KeyT, path: RedisValueT) -> CommandRequest[JsonType]:
|
|
122
|
+
"""
|
|
123
|
+
Toggles a boolean value
|
|
124
|
+
|
|
125
|
+
:param key: Redis key to modify.
|
|
126
|
+
:param path: JSONPath to specify.
|
|
127
|
+
:return: A list of integer replies for each path, the new value
|
|
128
|
+
(`0` if `false` or `1` if `true`), or ``None`` for JSON values matching
|
|
129
|
+
the path that are not Boolean.
|
|
130
|
+
"""
|
|
131
|
+
command_arguments: CommandArgList = [key, path]
|
|
132
|
+
return self.client.create_request(
|
|
133
|
+
CommandName.JSON_TOGGLE,
|
|
134
|
+
*command_arguments,
|
|
135
|
+
callback=JsonCallback(),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
@module_command(
|
|
139
|
+
CommandName.JSON_CLEAR,
|
|
140
|
+
group=COMMAND_GROUP,
|
|
141
|
+
version_introduced="2.0.0",
|
|
142
|
+
module=MODULE,
|
|
143
|
+
)
|
|
144
|
+
def clear(self, key: KeyT, path: RedisValueT | None = None) -> CommandRequest[int]:
|
|
145
|
+
"""
|
|
146
|
+
Clears all values from an array or an object and sets numeric values to `0`
|
|
147
|
+
|
|
148
|
+
:param key: The key to parse.
|
|
149
|
+
:param path: The JSONPath to specify.
|
|
150
|
+
:return: The number of values cleared.
|
|
151
|
+
"""
|
|
152
|
+
command_arguments: CommandArgList = [key]
|
|
153
|
+
if path:
|
|
154
|
+
command_arguments.append(path)
|
|
155
|
+
|
|
156
|
+
return self.client.create_request(
|
|
157
|
+
CommandName.JSON_CLEAR, *command_arguments, callback=IntCallback()
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
@module_command(
|
|
161
|
+
CommandName.JSON_SET,
|
|
162
|
+
group=COMMAND_GROUP,
|
|
163
|
+
version_introduced="1.0.0",
|
|
164
|
+
module=MODULE,
|
|
165
|
+
)
|
|
166
|
+
def set(
|
|
167
|
+
self,
|
|
168
|
+
key: KeyT,
|
|
169
|
+
path: RedisValueT,
|
|
170
|
+
value: JsonType,
|
|
171
|
+
condition: Literal[PureToken.NX, PureToken.XX] | None = None,
|
|
172
|
+
) -> CommandRequest[bool]:
|
|
173
|
+
"""
|
|
174
|
+
Sets or updates the JSON value at a path
|
|
175
|
+
|
|
176
|
+
:param key: The key to parse.
|
|
177
|
+
:param path: JSONPath to specify. For new Redis keys the ``path`` must be the root.
|
|
178
|
+
For existing keys, when the entire `path` exists, the value that it contains is replaced
|
|
179
|
+
with :paramref:`value`. For existing keys, when the ``path`` exists, except for the
|
|
180
|
+
last element, a new child is added with :paramref:`value`.
|
|
181
|
+
Adds a key (with its respective value) to a JSON Object (in a json data type key)
|
|
182
|
+
only if it is the last child in the ``path``, or it is the parent of a new child being
|
|
183
|
+
added in the ``path``. Optional argument :paramref:`condition` modifies this behavior
|
|
184
|
+
for both new json data type keys as well as the JSON Object keys in them.
|
|
185
|
+
:param value: Value to set at the specified :paramref:`path`.
|
|
186
|
+
:param condition: Optional argument to modify the behavior of adding a key to a JSON Object.
|
|
187
|
+
If ``NX``, the key is set only if it does not already exist. If ``XX``, the key is set only
|
|
188
|
+
if it already exists.
|
|
189
|
+
:return: `True` if the value was set successfully, `False` otherwise.
|
|
190
|
+
"""
|
|
191
|
+
command_arguments: CommandArgList = [key, path, json.dumps(value)]
|
|
192
|
+
if condition:
|
|
193
|
+
command_arguments.append(condition)
|
|
194
|
+
return self.client.create_request(
|
|
195
|
+
CommandName.JSON_SET, *command_arguments, callback=SimpleStringCallback()
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
@module_command(
|
|
199
|
+
CommandName.JSON_MGET,
|
|
200
|
+
group=COMMAND_GROUP,
|
|
201
|
+
version_introduced="1.0.0",
|
|
202
|
+
module=MODULE,
|
|
203
|
+
flags={CommandFlag.READONLY},
|
|
204
|
+
)
|
|
205
|
+
def mget(self, keys: Parameters[KeyT], path: StringT) -> CommandRequest[JsonType]:
|
|
206
|
+
"""
|
|
207
|
+
Returns the values at a path from one or more keys
|
|
208
|
+
|
|
209
|
+
:param keys: one or more keys to retrieve values from.
|
|
210
|
+
:param path: JSONPath to specify.
|
|
211
|
+
:return: The values at :paramref:`path` for each of the keys in :paramref:`keys`.
|
|
212
|
+
"""
|
|
213
|
+
command_arguments: CommandArgList = [*keys, path]
|
|
214
|
+
return self.client.create_request(
|
|
215
|
+
CommandName.JSON_MGET,
|
|
216
|
+
*command_arguments,
|
|
217
|
+
callback=JsonCallback(),
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
@module_command(
|
|
221
|
+
CommandName.JSON_MSET,
|
|
222
|
+
group=COMMAND_GROUP,
|
|
223
|
+
version_introduced="2.6.0",
|
|
224
|
+
module=MODULE,
|
|
225
|
+
)
|
|
226
|
+
def mset(self, triplets: Parameters[tuple[KeyT, StringT, JsonType]]) -> CommandRequest[bool]:
|
|
227
|
+
"""
|
|
228
|
+
Sets or updates the JSON value of one or more keys
|
|
229
|
+
|
|
230
|
+
:param triplets: Collection of triplets containing (``key``, ``path``, ``value``)
|
|
231
|
+
to set.
|
|
232
|
+
|
|
233
|
+
:return: `True` if all the values were set successfully
|
|
234
|
+
"""
|
|
235
|
+
command_arguments: CommandArgList = []
|
|
236
|
+
for key, path, value in triplets:
|
|
237
|
+
command_arguments.extend([key, path, json.dumps(value)])
|
|
238
|
+
|
|
239
|
+
return self.client.create_request(
|
|
240
|
+
CommandName.JSON_MSET, *command_arguments, callback=SimpleStringCallback()
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
@module_command(
|
|
244
|
+
CommandName.JSON_MERGE,
|
|
245
|
+
group=COMMAND_GROUP,
|
|
246
|
+
version_introduced="2.6.0",
|
|
247
|
+
module=MODULE,
|
|
248
|
+
)
|
|
249
|
+
def merge(self, key: KeyT, path: StringT, value: JsonType) -> CommandRequest[bool]:
|
|
250
|
+
"""
|
|
251
|
+
Merge a JSON object into an existing Redis key at a specified path.
|
|
252
|
+
|
|
253
|
+
:param key: The Redis key to merge the JSON object into.
|
|
254
|
+
:param path: The JSONPath within the Redis key to merge the JSON object into.
|
|
255
|
+
:param value: The JSON object to merge into the Redis key.
|
|
256
|
+
:return: True if the merge was successful, False otherwise.
|
|
257
|
+
"""
|
|
258
|
+
command_arguments: CommandArgList = [key, path, json.dumps(value)]
|
|
259
|
+
|
|
260
|
+
return self.client.create_request(
|
|
261
|
+
CommandName.JSON_MERGE, *command_arguments, callback=SimpleStringCallback()
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
@module_command(
|
|
265
|
+
CommandName.JSON_NUMINCRBY,
|
|
266
|
+
group=COMMAND_GROUP,
|
|
267
|
+
version_introduced="1.0.0",
|
|
268
|
+
module=MODULE,
|
|
269
|
+
)
|
|
270
|
+
def numincrby(
|
|
271
|
+
self, key: KeyT, path: RedisValueT, value: int | float
|
|
272
|
+
) -> CommandRequest[JsonType]:
|
|
273
|
+
"""
|
|
274
|
+
Increments the numeric value at path by a value
|
|
275
|
+
|
|
276
|
+
:param key: The key to modify.
|
|
277
|
+
:param path: The JSONPath to specify.
|
|
278
|
+
:param value: The number value to increment.
|
|
279
|
+
"""
|
|
280
|
+
command_arguments: CommandArgList = [key, path, value]
|
|
281
|
+
|
|
282
|
+
return self.client.create_request(
|
|
283
|
+
CommandName.JSON_NUMINCRBY, *command_arguments, callback=JsonCallback()
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
@module_command(
|
|
287
|
+
CommandName.JSON_NUMMULTBY,
|
|
288
|
+
group=COMMAND_GROUP,
|
|
289
|
+
version_introduced="1.0.0",
|
|
290
|
+
module=MODULE,
|
|
291
|
+
)
|
|
292
|
+
def nummultby(
|
|
293
|
+
self, key: KeyT, path: RedisValueT, value: int | float
|
|
294
|
+
) -> CommandRequest[JsonType]:
|
|
295
|
+
"""
|
|
296
|
+
Multiplies the numeric value at path by a value
|
|
297
|
+
|
|
298
|
+
:param key: Key to modify.
|
|
299
|
+
:param path: JSONPath to specify.
|
|
300
|
+
:param value: Number value to multiply.
|
|
301
|
+
"""
|
|
302
|
+
command_arguments: CommandArgList = [key, path, value]
|
|
303
|
+
|
|
304
|
+
return self.client.create_request(
|
|
305
|
+
CommandName.JSON_NUMMULTBY, *command_arguments, callback=JsonCallback()
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
@module_command(
|
|
309
|
+
CommandName.JSON_STRAPPEND,
|
|
310
|
+
group=COMMAND_GROUP,
|
|
311
|
+
version_introduced="1.0.0",
|
|
312
|
+
module=MODULE,
|
|
313
|
+
)
|
|
314
|
+
def strappend(
|
|
315
|
+
self,
|
|
316
|
+
key: KeyT,
|
|
317
|
+
value: str | bytes | int | float | None,
|
|
318
|
+
path: KeyT | None = None,
|
|
319
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
320
|
+
"""
|
|
321
|
+
Appends a string to a JSON string value at path
|
|
322
|
+
|
|
323
|
+
:param key: The key to modify
|
|
324
|
+
:param value: The value to append to the string(s) at the specified :paramref:`path`.
|
|
325
|
+
:param path: The JSONPath to specify the location of the string(s) to modify.
|
|
326
|
+
:return: A list of integer replies for each path, the string's new length,
|
|
327
|
+
or ``None`` if the matching JSON value is not a string.
|
|
328
|
+
"""
|
|
329
|
+
command_arguments: CommandArgList = [key]
|
|
330
|
+
if path is not None:
|
|
331
|
+
command_arguments.append(path)
|
|
332
|
+
command_arguments.append(json.dumps(value))
|
|
333
|
+
return self.client.create_request(
|
|
334
|
+
CommandName.JSON_STRAPPEND,
|
|
335
|
+
*command_arguments,
|
|
336
|
+
callback=OneOrManyCallback[int](),
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
@module_command(
|
|
340
|
+
CommandName.JSON_STRLEN,
|
|
341
|
+
group=COMMAND_GROUP,
|
|
342
|
+
version_introduced="1.0.0",
|
|
343
|
+
module=MODULE,
|
|
344
|
+
flags={CommandFlag.READONLY},
|
|
345
|
+
cacheable=True,
|
|
346
|
+
)
|
|
347
|
+
def strlen(
|
|
348
|
+
self, key: KeyT, path: KeyT | None = None
|
|
349
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
350
|
+
"""
|
|
351
|
+
Returns the length of the JSON String at path in key
|
|
352
|
+
|
|
353
|
+
:param key: The key of the JSON document.
|
|
354
|
+
:param path: JSONPath to specify.
|
|
355
|
+
:return: An array of integer replies for each path, the array's length,
|
|
356
|
+
or ``None``, if the matching JSON value is not a string.
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
"""
|
|
360
|
+
command_arguments: CommandArgList = [key]
|
|
361
|
+
if path is not None:
|
|
362
|
+
command_arguments.append(path)
|
|
363
|
+
|
|
364
|
+
return self.client.create_request(
|
|
365
|
+
CommandName.JSON_STRLEN,
|
|
366
|
+
*command_arguments,
|
|
367
|
+
callback=OneOrManyCallback[int](),
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
@module_command(
|
|
371
|
+
CommandName.JSON_ARRAPPEND,
|
|
372
|
+
group=COMMAND_GROUP,
|
|
373
|
+
version_introduced="1.0.0",
|
|
374
|
+
module=MODULE,
|
|
375
|
+
)
|
|
376
|
+
def arrappend(
|
|
377
|
+
self,
|
|
378
|
+
key: KeyT,
|
|
379
|
+
values: Parameters[JsonType],
|
|
380
|
+
path: KeyT | None = None,
|
|
381
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
382
|
+
"""
|
|
383
|
+
Append one or more json values into the array at path after the last element in it.
|
|
384
|
+
|
|
385
|
+
:param key: The key to modify.
|
|
386
|
+
:param values: One or more values to append to one or more arrays.
|
|
387
|
+
:param path: JSONPath to specify.
|
|
388
|
+
:return: An array of integer replies for each path, the array's new size,
|
|
389
|
+
or `None` if the matching JSON value is not an array.
|
|
390
|
+
|
|
391
|
+
"""
|
|
392
|
+
command_arguments: CommandArgList = [key]
|
|
393
|
+
if path:
|
|
394
|
+
command_arguments.append(path)
|
|
395
|
+
command_arguments.extend([json.dumps(value) for value in values])
|
|
396
|
+
return self.client.create_request(
|
|
397
|
+
CommandName.JSON_ARRAPPEND,
|
|
398
|
+
*command_arguments,
|
|
399
|
+
callback=OneOrManyCallback[int](),
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
@module_command(
|
|
403
|
+
CommandName.JSON_ARRINDEX,
|
|
404
|
+
group=COMMAND_GROUP,
|
|
405
|
+
version_introduced="1.0.0",
|
|
406
|
+
module=MODULE,
|
|
407
|
+
flags={CommandFlag.READONLY},
|
|
408
|
+
cacheable=True,
|
|
409
|
+
)
|
|
410
|
+
def arrindex(
|
|
411
|
+
self,
|
|
412
|
+
key: KeyT,
|
|
413
|
+
path: RedisValueT,
|
|
414
|
+
value: str | bytes | int | float,
|
|
415
|
+
start: int | None = None,
|
|
416
|
+
stop: int | None = None,
|
|
417
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
418
|
+
"""
|
|
419
|
+
Returns the index of the first occurrence of a JSON scalar value in the array at path
|
|
420
|
+
|
|
421
|
+
:param key: The key to parse.
|
|
422
|
+
:param path: The JSONPath to specify.
|
|
423
|
+
:param value: The value to find its index in one or more arrays.
|
|
424
|
+
:param start: Inclusive start value to specify in a slice of the array to search.
|
|
425
|
+
:param stop: Exclusive stop value to specify in a slice of the array to search,
|
|
426
|
+
including the last element. Negative values are interpreted as starting from the end.
|
|
427
|
+
:return: The index of the first occurrence of the value in the array,
|
|
428
|
+
or a list of indices if the value is found in multiple arrays.
|
|
429
|
+
"""
|
|
430
|
+
command_arguments: CommandArgList = [key, path, json.dumps(value)]
|
|
431
|
+
if start is not None:
|
|
432
|
+
command_arguments.append(start)
|
|
433
|
+
if stop is not None:
|
|
434
|
+
command_arguments.append(stop)
|
|
435
|
+
|
|
436
|
+
return self.client.create_request(
|
|
437
|
+
CommandName.JSON_ARRINDEX,
|
|
438
|
+
*command_arguments,
|
|
439
|
+
callback=OneOrManyCallback[int](),
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
@module_command(
|
|
443
|
+
CommandName.JSON_ARRINSERT,
|
|
444
|
+
group=COMMAND_GROUP,
|
|
445
|
+
version_introduced="1.0.0",
|
|
446
|
+
module=MODULE,
|
|
447
|
+
)
|
|
448
|
+
def arrinsert(
|
|
449
|
+
self,
|
|
450
|
+
key: KeyT,
|
|
451
|
+
path: RedisValueT,
|
|
452
|
+
index: int,
|
|
453
|
+
values: Parameters[JsonType],
|
|
454
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
455
|
+
"""
|
|
456
|
+
Inserts the JSON scalar(s) value at the specified index in the array at path
|
|
457
|
+
|
|
458
|
+
:param key: Key to modify.
|
|
459
|
+
:param path: JSONPath to specify.
|
|
460
|
+
:param index: Position in the array where you want to insert a value.
|
|
461
|
+
The index must be in the array's range. Inserting at `index` 0 prepends to the array.
|
|
462
|
+
Negative index values start from the end of the array.
|
|
463
|
+
:param values: One or more values to insert in one or more arrays.
|
|
464
|
+
:returns: The length of the array after the insert operation or a list of lengths of
|
|
465
|
+
the arrays after the insert operation if the path matches multiple arrays
|
|
466
|
+
"""
|
|
467
|
+
command_arguments: CommandArgList = [key, path, index]
|
|
468
|
+
command_arguments.extend([json.dumps(value) for value in values])
|
|
469
|
+
|
|
470
|
+
return self.client.create_request(
|
|
471
|
+
CommandName.JSON_ARRINSERT,
|
|
472
|
+
*command_arguments,
|
|
473
|
+
callback=OneOrManyCallback[int](),
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
@module_command(
|
|
477
|
+
CommandName.JSON_ARRLEN,
|
|
478
|
+
group=COMMAND_GROUP,
|
|
479
|
+
version_introduced="1.0.0",
|
|
480
|
+
module=MODULE,
|
|
481
|
+
flags={CommandFlag.READONLY},
|
|
482
|
+
cacheable=True,
|
|
483
|
+
)
|
|
484
|
+
def arrlen(
|
|
485
|
+
self, key: KeyT, path: KeyT | None = None
|
|
486
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
487
|
+
"""
|
|
488
|
+
Returns the length of the array at path
|
|
489
|
+
|
|
490
|
+
:param key: The key to parse.
|
|
491
|
+
:param path: The JSONPath to specify.
|
|
492
|
+
|
|
493
|
+
:return: An integer if the matching value is an array, or a list of integers if
|
|
494
|
+
multiple matching values are arrays. Returns ``None`` if the :paramref:`key` or
|
|
495
|
+
:paramref:`path` do not exist.
|
|
496
|
+
"""
|
|
497
|
+
command_arguments: CommandArgList = [key]
|
|
498
|
+
if path:
|
|
499
|
+
command_arguments.append(path)
|
|
500
|
+
|
|
501
|
+
return self.client.create_request(
|
|
502
|
+
CommandName.JSON_ARRLEN,
|
|
503
|
+
*command_arguments,
|
|
504
|
+
callback=OneOrManyCallback[int](),
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
@module_command(
|
|
508
|
+
CommandName.JSON_ARRPOP,
|
|
509
|
+
group=COMMAND_GROUP,
|
|
510
|
+
version_introduced="1.0.0",
|
|
511
|
+
module=MODULE,
|
|
512
|
+
)
|
|
513
|
+
def arrpop(
|
|
514
|
+
self, key: KeyT, path: KeyT | None = None, index: int | None = None
|
|
515
|
+
) -> CommandRequest[JsonType]:
|
|
516
|
+
"""
|
|
517
|
+
Removes and returns the element at the specified index in the array at path
|
|
518
|
+
|
|
519
|
+
:param key: Key to modify.
|
|
520
|
+
:param path: JSONPath to specify.
|
|
521
|
+
:param index: Position in the array to start popping from. Out-of-range indexes
|
|
522
|
+
round to their respective array ends.
|
|
523
|
+
:return: The popped value, or ``None`` if the matching JSON value is not an array.
|
|
524
|
+
"""
|
|
525
|
+
command_arguments: CommandArgList = [key]
|
|
526
|
+
if path:
|
|
527
|
+
command_arguments.append(path)
|
|
528
|
+
if index is not None:
|
|
529
|
+
command_arguments.append(index)
|
|
530
|
+
|
|
531
|
+
return self.client.create_request(
|
|
532
|
+
CommandName.JSON_ARRPOP, *command_arguments, callback=JsonCallback()
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
@module_command(
|
|
536
|
+
CommandName.JSON_ARRTRIM,
|
|
537
|
+
group=COMMAND_GROUP,
|
|
538
|
+
version_introduced="1.0.0",
|
|
539
|
+
module=MODULE,
|
|
540
|
+
)
|
|
541
|
+
def arrtrim(
|
|
542
|
+
self, key: KeyT, path: RedisValueT, start: int, stop: int
|
|
543
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
544
|
+
"""
|
|
545
|
+
Trims the array at path to contain only the specified inclusive range of indices
|
|
546
|
+
from start to stop
|
|
547
|
+
|
|
548
|
+
:param key: Key to modify.
|
|
549
|
+
:param path: The JSONPath to specify.
|
|
550
|
+
:param start: The index of the first element to keep (previous elements are trimmed).
|
|
551
|
+
:param stop: The index of the last element to keep (following elements are trimmed),
|
|
552
|
+
including the last element. Negative values are interpreted as starting from the end.
|
|
553
|
+
:return: The number of elements removed or a list if multiple matching values are arrays.
|
|
554
|
+
"""
|
|
555
|
+
command_arguments: CommandArgList = [key, path, start, stop]
|
|
556
|
+
|
|
557
|
+
return self.client.create_request(
|
|
558
|
+
CommandName.JSON_ARRTRIM,
|
|
559
|
+
*command_arguments,
|
|
560
|
+
callback=OneOrManyCallback[int](),
|
|
561
|
+
)
|
|
562
|
+
|
|
563
|
+
@module_command(
|
|
564
|
+
CommandName.JSON_OBJKEYS,
|
|
565
|
+
group=COMMAND_GROUP,
|
|
566
|
+
version_introduced="1.0.0",
|
|
567
|
+
module=MODULE,
|
|
568
|
+
)
|
|
569
|
+
def objkeys(self, key: KeyT, path: StringT | None = None) -> CommandRequest[ResponseType]:
|
|
570
|
+
"""
|
|
571
|
+
Returns the JSON keys of the object at path
|
|
572
|
+
|
|
573
|
+
:param key: The key of the JSON document.
|
|
574
|
+
:param path: JSONPath to specify.
|
|
575
|
+
|
|
576
|
+
:return: A list of the key names in the object or a list of lists if multiple objects
|
|
577
|
+
match the :paramref:`path`, or `None` if the matching value is not an object.
|
|
578
|
+
|
|
579
|
+
"""
|
|
580
|
+
command_arguments: CommandArgList = [key]
|
|
581
|
+
if path:
|
|
582
|
+
command_arguments.append(path)
|
|
583
|
+
|
|
584
|
+
return self.client.create_request(
|
|
585
|
+
CommandName.JSON_OBJKEYS,
|
|
586
|
+
*command_arguments,
|
|
587
|
+
callback=NoopCallback[ResponseType](),
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
@module_command(
|
|
591
|
+
CommandName.JSON_OBJLEN,
|
|
592
|
+
group=COMMAND_GROUP,
|
|
593
|
+
version_introduced="1.0.0",
|
|
594
|
+
module=MODULE,
|
|
595
|
+
)
|
|
596
|
+
def objlen(
|
|
597
|
+
self, key: KeyT, path: KeyT | None = None
|
|
598
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
599
|
+
"""
|
|
600
|
+
Returns the number of keys of the object at path
|
|
601
|
+
|
|
602
|
+
:param key: The key of the JSON document.
|
|
603
|
+
:param path: JSONPath to specify.
|
|
604
|
+
:return: An integer if the path matches exactly one object or a list of integer
|
|
605
|
+
replies for each path specified as the number of keys in the object or ``None``,
|
|
606
|
+
if the matching JSON value is not an object.
|
|
607
|
+
"""
|
|
608
|
+
command_arguments: CommandArgList = [key]
|
|
609
|
+
if path:
|
|
610
|
+
command_arguments.append(path)
|
|
611
|
+
|
|
612
|
+
return self.client.create_request(
|
|
613
|
+
CommandName.JSON_OBJLEN,
|
|
614
|
+
*command_arguments,
|
|
615
|
+
callback=OneOrManyCallback[int](),
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
@module_command(
|
|
619
|
+
CommandName.JSON_TYPE,
|
|
620
|
+
group=COMMAND_GROUP,
|
|
621
|
+
version_introduced="1.0.0",
|
|
622
|
+
module=MODULE,
|
|
623
|
+
flags={CommandFlag.READONLY},
|
|
624
|
+
cacheable=True,
|
|
625
|
+
)
|
|
626
|
+
def type(
|
|
627
|
+
self, key: KeyT, path: KeyT | None = None
|
|
628
|
+
) -> CommandRequest[AnyStr | list[AnyStr | None] | None]:
|
|
629
|
+
"""
|
|
630
|
+
Returns the type of the JSON value at path
|
|
631
|
+
|
|
632
|
+
:param key: The key to parse.
|
|
633
|
+
:param path: The JSONPath to specify.
|
|
634
|
+
"""
|
|
635
|
+
command_arguments: CommandArgList = [key]
|
|
636
|
+
if path is not None:
|
|
637
|
+
command_arguments.append(path)
|
|
638
|
+
|
|
639
|
+
return self.client.create_request(
|
|
640
|
+
CommandName.JSON_TYPE,
|
|
641
|
+
*command_arguments,
|
|
642
|
+
callback=OneOrManyCallback[AnyStr](),
|
|
643
|
+
)
|
|
644
|
+
|
|
645
|
+
@module_command(
|
|
646
|
+
CommandName.JSON_RESP,
|
|
647
|
+
group=COMMAND_GROUP,
|
|
648
|
+
version_introduced="1.0.0",
|
|
649
|
+
version_deprecated="2.6.0",
|
|
650
|
+
module=MODULE,
|
|
651
|
+
flags={CommandFlag.READONLY},
|
|
652
|
+
)
|
|
653
|
+
def resp(self, key: KeyT, path: KeyT | None = None) -> CommandRequest[ResponseType]:
|
|
654
|
+
"""
|
|
655
|
+
Returns the JSON value at path in Redis Serialization Protocol (RESP)
|
|
656
|
+
|
|
657
|
+
:param key: The key to parse.
|
|
658
|
+
:param path: The JSONPath to specify.
|
|
659
|
+
"""
|
|
660
|
+
command_arguments: CommandArgList = [key]
|
|
661
|
+
if path:
|
|
662
|
+
command_arguments.append(path)
|
|
663
|
+
|
|
664
|
+
return self.client.create_request(
|
|
665
|
+
CommandName.JSON_RESP,
|
|
666
|
+
*command_arguments,
|
|
667
|
+
callback=NoopCallback[ResponseType](),
|
|
668
|
+
)
|
|
669
|
+
|
|
670
|
+
@module_command(
|
|
671
|
+
CommandName.JSON_DEBUG_MEMORY,
|
|
672
|
+
group=COMMAND_GROUP,
|
|
673
|
+
version_introduced="1.0.0",
|
|
674
|
+
module=MODULE,
|
|
675
|
+
flags={CommandFlag.READONLY},
|
|
676
|
+
)
|
|
677
|
+
def debug_memory(
|
|
678
|
+
self, key: KeyT, path: KeyT | None = None
|
|
679
|
+
) -> CommandRequest[int | list[int | None] | None]:
|
|
680
|
+
"""
|
|
681
|
+
Reports the size in bytes of a key
|
|
682
|
+
"""
|
|
683
|
+
command_arguments: CommandArgList = [key]
|
|
684
|
+
if path:
|
|
685
|
+
command_arguments.append(path)
|
|
686
|
+
|
|
687
|
+
return self.client.create_request(
|
|
688
|
+
CommandName.JSON_DEBUG_MEMORY,
|
|
689
|
+
*command_arguments,
|
|
690
|
+
callback=OneOrManyCallback[int](),
|
|
691
|
+
)
|
|
File without changes
|
|
File without changes
|