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,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