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