valkey-glide 2.2.0rc1__cp312-cp312-macosx_10_7_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- glide/__init__.py +388 -0
- glide/async_commands/__init__.py +5 -0
- glide/async_commands/cluster_commands.py +1476 -0
- glide/async_commands/core.py +7818 -0
- glide/async_commands/ft.py +465 -0
- glide/async_commands/glide_json.py +1269 -0
- glide/async_commands/standalone_commands.py +1001 -0
- glide/glide.cpython-312-darwin.so +0 -0
- glide/glide.pyi +61 -0
- glide/glide_client.py +821 -0
- glide/logger.py +97 -0
- glide/opentelemetry.py +185 -0
- glide/py.typed +0 -0
- glide_shared/__init__.py +330 -0
- glide_shared/commands/__init__.py +0 -0
- glide_shared/commands/batch.py +5997 -0
- glide_shared/commands/batch_options.py +261 -0
- glide_shared/commands/bitmap.py +320 -0
- glide_shared/commands/command_args.py +103 -0
- glide_shared/commands/core_options.py +407 -0
- glide_shared/commands/server_modules/ft_options/ft_aggregate_options.py +300 -0
- glide_shared/commands/server_modules/ft_options/ft_constants.py +84 -0
- glide_shared/commands/server_modules/ft_options/ft_create_options.py +423 -0
- glide_shared/commands/server_modules/ft_options/ft_profile_options.py +113 -0
- glide_shared/commands/server_modules/ft_options/ft_search_options.py +139 -0
- glide_shared/commands/server_modules/json_batch.py +820 -0
- glide_shared/commands/server_modules/json_options.py +93 -0
- glide_shared/commands/sorted_set.py +412 -0
- glide_shared/commands/stream.py +449 -0
- glide_shared/config.py +975 -0
- glide_shared/constants.py +124 -0
- glide_shared/exceptions.py +88 -0
- glide_shared/protobuf/command_request_pb2.py +56 -0
- glide_shared/protobuf/connection_request_pb2.py +56 -0
- glide_shared/protobuf/response_pb2.py +32 -0
- glide_shared/protobuf_codec.py +110 -0
- glide_shared/routes.py +161 -0
- valkey_glide-2.2.0rc1.dist-info/METADATA +210 -0
- valkey_glide-2.2.0rc1.dist-info/RECORD +40 -0
- valkey_glide-2.2.0rc1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
|
+
"""Glide module for `JSON` commands in batch.
|
|
3
|
+
|
|
4
|
+
Examples:
|
|
5
|
+
>>> import json
|
|
6
|
+
>>> from glide import json_batch
|
|
7
|
+
>>> batch = ClusterBatch(is_atomic=True)
|
|
8
|
+
>>> value = {'a': 1.0, 'b': 2}
|
|
9
|
+
>>> json_str = json.dumps(value) # Convert Python dictionary to JSON string using json.dumps()
|
|
10
|
+
>>> json_batch.set(batch, "doc", "$", json_str)
|
|
11
|
+
>>> json_batch.get(batch, "doc", "$") # Returns the value at path '$' in the JSON document stored at `doc` as
|
|
12
|
+
# JSON string.
|
|
13
|
+
>>> result = await glide_client.exec(batch)
|
|
14
|
+
>>> print result[0] # set result
|
|
15
|
+
'OK' # Indicates successful setting of the value at path '$' in the key stored at `doc`.
|
|
16
|
+
>>> print result[1] # get result
|
|
17
|
+
b"[{\"a\":1.0,\"b\":2}]"
|
|
18
|
+
>>> print json.loads(str(result[1]))
|
|
19
|
+
[{"a": 1.0, "b": 2}] # JSON object retrieved from the key `doc` using json.loads()
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from typing import List, Optional, Union
|
|
24
|
+
|
|
25
|
+
from glide_shared.commands.batch import TBatch
|
|
26
|
+
from glide_shared.commands.core_options import ConditionalChange
|
|
27
|
+
from glide_shared.commands.server_modules.json_options import (
|
|
28
|
+
JsonArrIndexOptions,
|
|
29
|
+
JsonArrPopOptions,
|
|
30
|
+
JsonGetOptions,
|
|
31
|
+
)
|
|
32
|
+
from glide_shared.constants import TEncodable
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def set(
|
|
36
|
+
batch: TBatch,
|
|
37
|
+
key: TEncodable,
|
|
38
|
+
path: TEncodable,
|
|
39
|
+
value: TEncodable,
|
|
40
|
+
set_condition: Optional[ConditionalChange] = None,
|
|
41
|
+
) -> TBatch:
|
|
42
|
+
"""
|
|
43
|
+
Sets the JSON value at the specified `path` stored at `key`.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
batch (TBatch): The batch to execute the command.
|
|
47
|
+
key (TEncodable): The key of the JSON document.
|
|
48
|
+
path (TEncodable): Represents the path within the JSON document where the value will be set.
|
|
49
|
+
The key will be modified only if `value` is added as the last child in the specified `path`, or if the specified
|
|
50
|
+
`path` acts as the parent of a new child being added.
|
|
51
|
+
value (TEncodable): The value to set at the specific path, in JSON formatted bytes or str.
|
|
52
|
+
set_condition (Optional[ConditionalChange]): Set the value only if the given condition is met (within the key or path).
|
|
53
|
+
Equivalent to [`XX` | `NX`] in the RESP API. Defaults to None.
|
|
54
|
+
|
|
55
|
+
Command response:
|
|
56
|
+
Optional[TOK]: If the value is successfully set, returns OK.
|
|
57
|
+
If `value` isn't set because of `set_condition`, returns None.
|
|
58
|
+
"""
|
|
59
|
+
args = ["JSON.SET", key, path, value]
|
|
60
|
+
if set_condition:
|
|
61
|
+
args.append(set_condition.value)
|
|
62
|
+
|
|
63
|
+
return batch.custom_command(args)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get(
|
|
67
|
+
batch: TBatch,
|
|
68
|
+
key: TEncodable,
|
|
69
|
+
paths: Optional[Union[TEncodable, List[TEncodable]]] = None,
|
|
70
|
+
options: Optional[JsonGetOptions] = None,
|
|
71
|
+
) -> TBatch:
|
|
72
|
+
"""
|
|
73
|
+
Retrieves the JSON value at the specified `paths` stored at `key`.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
batch (TBatch): The batch to execute the command.
|
|
77
|
+
key (TEncodable): The key of the JSON document.
|
|
78
|
+
paths (Optional[Union[TEncodable, List[TEncodable]]]): The path or list of paths within the JSON document.
|
|
79
|
+
Default to None.
|
|
80
|
+
options (Optional[JsonGetOptions]): Options for formatting the byte representation of the JSON data.
|
|
81
|
+
See `JsonGetOptions`.
|
|
82
|
+
|
|
83
|
+
Command response:
|
|
84
|
+
TJsonResponse[Optional[bytes]]:
|
|
85
|
+
If one path is given:
|
|
86
|
+
For JSONPath (path starts with `$`):
|
|
87
|
+
Returns a stringified JSON list of bytes replies for every possible path,
|
|
88
|
+
or a byte string representation of an empty array, if path doesn't exists.
|
|
89
|
+
If `key` doesn't exist, returns None.
|
|
90
|
+
For legacy path (path doesn't start with `$`):
|
|
91
|
+
Returns a byte string representation of the value in `path`.
|
|
92
|
+
If `path` doesn't exist, an error is raised.
|
|
93
|
+
If `key` doesn't exist, returns None.
|
|
94
|
+
If multiple paths are given:
|
|
95
|
+
Returns a stringified JSON object in bytes, in which each path is a key, and it's corresponding value, is the
|
|
96
|
+
value as if the path was executed in the command as a single path.
|
|
97
|
+
In case of multiple paths, and `paths` are a mix of both JSONPath and legacy path, the command behaves as if all are
|
|
98
|
+
JSONPath paths.
|
|
99
|
+
For more information about the returned type, see `TJsonResponse`.
|
|
100
|
+
"""
|
|
101
|
+
args = ["JSON.GET", key]
|
|
102
|
+
if options:
|
|
103
|
+
args.extend(options.get_options())
|
|
104
|
+
if paths:
|
|
105
|
+
if isinstance(paths, (str, bytes)):
|
|
106
|
+
paths = [paths]
|
|
107
|
+
args.extend(paths)
|
|
108
|
+
|
|
109
|
+
return batch.custom_command(args)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def mget(
|
|
113
|
+
batch: TBatch,
|
|
114
|
+
keys: List[TEncodable],
|
|
115
|
+
path: TEncodable,
|
|
116
|
+
) -> TBatch:
|
|
117
|
+
"""
|
|
118
|
+
Retrieves the JSON values at the specified `path` stored at multiple `keys`.
|
|
119
|
+
|
|
120
|
+
Note:
|
|
121
|
+
When in cluster mode:
|
|
122
|
+
- If the batch is an atomic batch (transaction), then all keys must map to the same slot.
|
|
123
|
+
- If the batch is a non-atomic batch (pipeline), and the keys map to different hash slots,
|
|
124
|
+
the command will be split across these slots and executed separately for each.
|
|
125
|
+
This means the command is atomic only at the slot level. If one or more slot-specific
|
|
126
|
+
requests fail, the entire call will return the first encountered error, even
|
|
127
|
+
though some requests may have succeeded while others did not.
|
|
128
|
+
If this behavior impacts your application logic, consider splitting the
|
|
129
|
+
request into sub-requests per slot to ensure atomicity.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
batch (TBatch): The batch to execute the command.
|
|
133
|
+
keys (List[TEncodable]): A list of keys for the JSON documents.
|
|
134
|
+
path (TEncodable): The path within the JSON documents.
|
|
135
|
+
|
|
136
|
+
Command response:
|
|
137
|
+
List[Optional[bytes]]:
|
|
138
|
+
For JSONPath (`path` starts with `$`):
|
|
139
|
+
Returns a list of byte representations of the values found at the given path for each key.
|
|
140
|
+
If `path` does not exist within the key, the entry will be an empty array.
|
|
141
|
+
For legacy path (`path` doesn't starts with `$`):
|
|
142
|
+
Returns a list of byte representations of the values found at the given path for each key.
|
|
143
|
+
If `path` does not exist within the key, the entry will be None.
|
|
144
|
+
If a key doesn't exist, the corresponding list element will be None.
|
|
145
|
+
"""
|
|
146
|
+
args = ["JSON.MGET"] + keys + [path]
|
|
147
|
+
return batch.custom_command(args)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def arrappend(
|
|
151
|
+
batch: TBatch,
|
|
152
|
+
key: TEncodable,
|
|
153
|
+
path: TEncodable,
|
|
154
|
+
values: List[TEncodable],
|
|
155
|
+
) -> TBatch:
|
|
156
|
+
"""
|
|
157
|
+
Appends one or more `values` to the JSON array at the specified `path` within the JSON document stored at `key`.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
batch (TBatch): The batch to execute the command.
|
|
161
|
+
key (TEncodable): The key of the JSON document.
|
|
162
|
+
path (TEncodable): Represents the path within the JSON document where the `values` will be appended.
|
|
163
|
+
values (TEncodable): The values to append to the JSON array at the specified path.
|
|
164
|
+
JSON string values must be wrapped with quotes. For example, to append `"foo"`, pass `"\"foo\""`.
|
|
165
|
+
|
|
166
|
+
Command response:
|
|
167
|
+
TJsonResponse[int]:
|
|
168
|
+
For JSONPath (`path` starts with `$`):
|
|
169
|
+
Returns a list of integer replies for every possible path, indicating the new length of the array after
|
|
170
|
+
appending `values`, or None for JSON values matching the path that are not an array.
|
|
171
|
+
If `path` doesn't exist, an empty array will be returned.
|
|
172
|
+
For legacy path (`path` doesn't start with `$`):
|
|
173
|
+
Returns the length of the array after appending `values` to the array at `path`.
|
|
174
|
+
If multiple paths match, the length of the first updated array is returned.
|
|
175
|
+
If the JSON value at `path` is not a array or if `path` doesn't exist, an error is raised.
|
|
176
|
+
If `key` doesn't exist, an error is raised.
|
|
177
|
+
For more information about the returned type, see `TJsonResponse`.
|
|
178
|
+
"""
|
|
179
|
+
args = ["JSON.ARRAPPEND", key, path] + values
|
|
180
|
+
return batch.custom_command(args)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def arrindex(
|
|
184
|
+
batch: TBatch,
|
|
185
|
+
key: TEncodable,
|
|
186
|
+
path: TEncodable,
|
|
187
|
+
value: TEncodable,
|
|
188
|
+
options: Optional[JsonArrIndexOptions] = None,
|
|
189
|
+
) -> TBatch:
|
|
190
|
+
"""
|
|
191
|
+
Searches for the first occurrence of a scalar JSON value (i.e., a value that is neither an object nor an array) within
|
|
192
|
+
arrays at the specified `path` in the JSON document stored at `key`.
|
|
193
|
+
|
|
194
|
+
If specified, `options.start` and `options.end` define an inclusive-to-exclusive search range within the array.
|
|
195
|
+
(Where `options.start` is inclusive and `options.end` is exclusive).
|
|
196
|
+
|
|
197
|
+
Out-of-range indices adjust to the nearest valid position, and negative values count from the end
|
|
198
|
+
(e.g., `-1` is the last element, `-2` the second last).
|
|
199
|
+
|
|
200
|
+
Setting `options.end` to `0` behaves like `-1`, extending the range to the array's end (inclusive).
|
|
201
|
+
|
|
202
|
+
If `options.start` exceeds `options.end`, `-1` is returned, indicating that the value was not found.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
batch (TBatch): The batch to execute the command.
|
|
206
|
+
key (TEncodable): The key of the JSON document.
|
|
207
|
+
path (TEncodable): The path within the JSON document.
|
|
208
|
+
value (TEncodable): The value to search for within the arrays.
|
|
209
|
+
options (Optional[JsonArrIndexOptions]): Options specifying an inclusive `start` index and an optional exclusive `end`
|
|
210
|
+
index for a range-limited search.
|
|
211
|
+
Defaults to the full array if not provided. See `JsonArrIndexOptions`.
|
|
212
|
+
|
|
213
|
+
Command response:
|
|
214
|
+
Optional[Union[int, List[int]]]:
|
|
215
|
+
For JSONPath (`path` starts with `$`):
|
|
216
|
+
Returns an array of integers for every possible path, indicating of the first occurrence of `value` within the
|
|
217
|
+
array, or None for JSON values matching the path that are not an array.
|
|
218
|
+
A returned value of `-1` indicates that the value was not found in that particular array.
|
|
219
|
+
If `path` does not exist, an empty array will be returned.
|
|
220
|
+
For legacy path (`path` doesn't start with `$`):
|
|
221
|
+
Returns an integer representing the index of the first occurrence of `value` within the array at the specified
|
|
222
|
+
path.
|
|
223
|
+
A returned value of `-1` indicates that the value was not found in that particular array.
|
|
224
|
+
If multiple paths match, the index of the value from the first matching array is returned.
|
|
225
|
+
If the JSON value at the `path` is not an array or if `path` does not exist, an error is raised.
|
|
226
|
+
If `key` does not exist, an error is raised.
|
|
227
|
+
"""
|
|
228
|
+
args = ["JSON.ARRINDEX", key, path, value]
|
|
229
|
+
|
|
230
|
+
if options:
|
|
231
|
+
args.extend(options.to_args())
|
|
232
|
+
|
|
233
|
+
return batch.custom_command(args)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def arrinsert(
|
|
237
|
+
batch: TBatch,
|
|
238
|
+
key: TEncodable,
|
|
239
|
+
path: TEncodable,
|
|
240
|
+
index: int,
|
|
241
|
+
values: List[TEncodable],
|
|
242
|
+
) -> TBatch:
|
|
243
|
+
"""
|
|
244
|
+
Inserts one or more values into the array at the specified `path` within the JSON document stored at `key`, before the
|
|
245
|
+
given `index`.
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
batch (TBatch): The batch to execute the command.
|
|
249
|
+
key (TEncodable): The key of the JSON document.
|
|
250
|
+
path (TEncodable): The path within the JSON document.
|
|
251
|
+
index (int): The array index before which values are inserted.
|
|
252
|
+
values (List[TEncodable]): The JSON values to be inserted into the array, in JSON formatted bytes or str.
|
|
253
|
+
Json string values must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
|
|
254
|
+
|
|
255
|
+
Command response:
|
|
256
|
+
TJsonResponse[int]:
|
|
257
|
+
For JSONPath (`path` starts with '$'):
|
|
258
|
+
Returns a list of integer replies for every possible path, indicating the new length of the array,
|
|
259
|
+
or None for JSON values matching the path that are not an array.
|
|
260
|
+
If `path` does not exist, an empty array will be returned.
|
|
261
|
+
For legacy path (`path` doesn't start with '$'):
|
|
262
|
+
Returns an integer representing the new length of the array.
|
|
263
|
+
If multiple paths are matched, returns the length of the first modified array.
|
|
264
|
+
If `path` doesn't exist or the value at `path` is not an array, an error is raised.
|
|
265
|
+
If the index is out of bounds, an error is raised.
|
|
266
|
+
If `key` doesn't exist, an error is raised.
|
|
267
|
+
"""
|
|
268
|
+
args = ["JSON.ARRINSERT", key, path, str(index)] + values
|
|
269
|
+
return batch.custom_command(args)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def arrlen(
|
|
273
|
+
batch: TBatch,
|
|
274
|
+
key: TEncodable,
|
|
275
|
+
path: Optional[TEncodable] = None,
|
|
276
|
+
) -> TBatch:
|
|
277
|
+
"""
|
|
278
|
+
Retrieves the length of the array at the specified `path` within the JSON document stored at `key`.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
batch (TBatch): The batch to execute the command.
|
|
282
|
+
key (TEncodable): The key of the JSON document.
|
|
283
|
+
path (Optional[TEncodable]): The path within the JSON document. Defaults to None.
|
|
284
|
+
|
|
285
|
+
Command response:
|
|
286
|
+
Optional[TJsonResponse[int]]:
|
|
287
|
+
For JSONPath (`path` starts with `$`):
|
|
288
|
+
Returns a list of integer replies for every possible path, indicating the length of the array,
|
|
289
|
+
or None for JSON values matching the path that are not an array.
|
|
290
|
+
If `path` doesn't exist, an empty array will be returned.
|
|
291
|
+
For legacy path (`path` doesn't starts with `$`):
|
|
292
|
+
Returns the length of the array at `path`.
|
|
293
|
+
If multiple paths match, the length of the first array match is returned.
|
|
294
|
+
If the JSON value at `path` is not a array or if `path` doesn't exist, an error is raised.
|
|
295
|
+
If `key` doesn't exist, None is returned.
|
|
296
|
+
"""
|
|
297
|
+
args = ["JSON.ARRLEN", key]
|
|
298
|
+
if path:
|
|
299
|
+
args.append(path)
|
|
300
|
+
return batch.custom_command(args)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def arrpop(
|
|
304
|
+
batch: TBatch,
|
|
305
|
+
key: TEncodable,
|
|
306
|
+
options: Optional[JsonArrPopOptions] = None,
|
|
307
|
+
) -> TBatch:
|
|
308
|
+
"""
|
|
309
|
+
Pops an element from the array located at the specified path within the JSON document stored at `key`.
|
|
310
|
+
If `options.index` is provided, it pops the element at that index instead of the last element.
|
|
311
|
+
|
|
312
|
+
Args:
|
|
313
|
+
batch (TBatch): The batch to execute the command.
|
|
314
|
+
key (TEncodable): The key of the JSON document.
|
|
315
|
+
options (Optional[JsonArrPopOptions]): Options including the path and optional index. See `JsonArrPopOptions`.
|
|
316
|
+
Default to None.
|
|
317
|
+
If not specified, attempts to pop the last element from the root value if it's an array.
|
|
318
|
+
If the root value is not an array, an error will be raised.
|
|
319
|
+
|
|
320
|
+
Command response:
|
|
321
|
+
Optional[TJsonResponse[bytes]]:
|
|
322
|
+
For JSONPath (`options.path` starts with `$`):
|
|
323
|
+
Returns a list of bytes string replies for every possible path, representing the popped JSON values,
|
|
324
|
+
or None for JSON values matching the path that are not an array or are an empty array.
|
|
325
|
+
If `options.path` doesn't exist, an empty list will be returned.
|
|
326
|
+
For legacy path (`options.path` doesn't starts with `$`):
|
|
327
|
+
Returns a bytes string representing the popped JSON value, or None if the array at `options.path` is empty.
|
|
328
|
+
If multiple paths match, the value from the first matching array that is not empty is returned.
|
|
329
|
+
If the JSON value at `options.path` is not a array or if `options.path` doesn't exist, an error is raised.
|
|
330
|
+
If `key` doesn't exist, an error is raised.
|
|
331
|
+
"""
|
|
332
|
+
args = ["JSON.ARRPOP", key]
|
|
333
|
+
if options:
|
|
334
|
+
args.extend(options.to_args())
|
|
335
|
+
|
|
336
|
+
return batch.custom_command(args)
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def arrtrim(
|
|
340
|
+
batch: TBatch,
|
|
341
|
+
key: TEncodable,
|
|
342
|
+
path: TEncodable,
|
|
343
|
+
start: int,
|
|
344
|
+
end: int,
|
|
345
|
+
) -> TBatch:
|
|
346
|
+
"""
|
|
347
|
+
Trims an array at the specified `path` within the JSON document stored at `key` so that it becomes a subarray
|
|
348
|
+
[start, end], both inclusive.
|
|
349
|
+
If `start` < 0, it is treated as 0.
|
|
350
|
+
If `end` >= size (size of the array), it is treated as size-1.
|
|
351
|
+
If `start` >= size or `start` > `end`, the array is emptied and 0 is returned.
|
|
352
|
+
|
|
353
|
+
Args:
|
|
354
|
+
batch (TBatch): The batch to execute the command.
|
|
355
|
+
key (TEncodable): The key of the JSON document.
|
|
356
|
+
path (TEncodable): The path within the JSON document.
|
|
357
|
+
start (int): The start index, inclusive.
|
|
358
|
+
end (int): The end index, inclusive.
|
|
359
|
+
|
|
360
|
+
Command response:
|
|
361
|
+
TJsonResponse[int]:
|
|
362
|
+
For JSONPath (`path` starts with '$'):
|
|
363
|
+
Returns a list of integer replies for every possible path, indicating the new length of the array, or None for
|
|
364
|
+
JSON values matching the path that are not an array.
|
|
365
|
+
If a value is an empty array, its corresponding return value is 0.
|
|
366
|
+
If `path` doesn't exist, an empty array will be returned.
|
|
367
|
+
For legacy path (`path` doesn't starts with `$`):
|
|
368
|
+
Returns an integer representing the new length of the array.
|
|
369
|
+
If the array is empty, returns 0.
|
|
370
|
+
If multiple paths match, the length of the first trimmed array match is returned.
|
|
371
|
+
If `path` doesn't exist, or the value at `path` is not an array, an error is raised.
|
|
372
|
+
If `key` doesn't exist, an error is raised.
|
|
373
|
+
"""
|
|
374
|
+
|
|
375
|
+
return batch.custom_command(["JSON.ARRTRIM", key, path, str(start), str(end)])
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def clear(
|
|
379
|
+
batch: TBatch,
|
|
380
|
+
key: TEncodable,
|
|
381
|
+
path: Optional[str] = None,
|
|
382
|
+
) -> TBatch:
|
|
383
|
+
"""
|
|
384
|
+
Clears arrays or objects at the specified JSON path in the document stored at `key`.
|
|
385
|
+
Numeric values are set to `0`, and boolean values are set to `False`, and string values are converted to empty strings.
|
|
386
|
+
|
|
387
|
+
Args:
|
|
388
|
+
batch (TBatch): The batch to execute the command.
|
|
389
|
+
key (TEncodable): The key of the JSON document.
|
|
390
|
+
path (Optional[str]): The path within the JSON document. Default to None.
|
|
391
|
+
|
|
392
|
+
Command response:
|
|
393
|
+
int: The number of containers cleared, numeric values zeroed, and booleans toggled to `false`,
|
|
394
|
+
and string values converted to empty strings.
|
|
395
|
+
If `path` doesn't exist, or the value at `path` is already empty (e.g., an empty array, object, or string),
|
|
396
|
+
0 is returned.
|
|
397
|
+
If `key doesn't exist, an error is raised.
|
|
398
|
+
"""
|
|
399
|
+
args = ["JSON.CLEAR", key]
|
|
400
|
+
if path:
|
|
401
|
+
args.append(path)
|
|
402
|
+
|
|
403
|
+
return batch.custom_command(args)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def debug_fields(
|
|
407
|
+
batch: TBatch,
|
|
408
|
+
key: TEncodable,
|
|
409
|
+
path: Optional[TEncodable] = None,
|
|
410
|
+
) -> TBatch:
|
|
411
|
+
"""
|
|
412
|
+
Returns the number of fields of the JSON value at the specified `path` within the JSON document stored at `key`.
|
|
413
|
+
- **Primitive Values**: Each non-container JSON value (e.g., strings, numbers, booleans, and null) counts as one field.
|
|
414
|
+
- **Arrays and Objects:**: Each item in an array and each key-value pair in an object is counted as one field.
|
|
415
|
+
(Each top-level value counts as one field, regardless of it's type.)
|
|
416
|
+
- Their nested values are counted recursively and added to the total.
|
|
417
|
+
- **Example**: For the JSON `{"a": 1, "b": [2, 3, {"c": 4}]}`, the count would be:
|
|
418
|
+
- Top-level: 2 fields (`"a"` and `"b"`)
|
|
419
|
+
- Nested: 3 fields in the array (`2`, `3`, and `{"c": 4}`) plus 1 for the object (`"c"`)
|
|
420
|
+
- Total: 2 (top-level) + 3 (from array) + 1 (from nested object) = 6 fields.
|
|
421
|
+
|
|
422
|
+
Args:
|
|
423
|
+
batch (TBatch): The batch to execute the command.
|
|
424
|
+
key (TEncodable): The key of the JSON document.
|
|
425
|
+
path (Optional[TEncodable]): The path within the JSON document. Defaults to root if not provided.
|
|
426
|
+
|
|
427
|
+
Command response:
|
|
428
|
+
Optional[TJsonUniversalResponse[int]]:
|
|
429
|
+
For JSONPath (`path` starts with `$`):
|
|
430
|
+
Returns an array of integers, each indicating the number of fields for each matched `path`.
|
|
431
|
+
If `path` doesn't exist, an empty array will be returned.
|
|
432
|
+
For legacy path (`path` doesn't start with `$`):
|
|
433
|
+
Returns an integer indicating the number of fields for each matched `path`.
|
|
434
|
+
If multiple paths match, number of fields of the first JSON value match is returned.
|
|
435
|
+
If `path` doesn't exist, an error is raised.
|
|
436
|
+
If `path` is not provided, it reports the total number of fields in the entire JSON document.
|
|
437
|
+
If `key` doesn't exist, None is returned.
|
|
438
|
+
"""
|
|
439
|
+
args = ["JSON.DEBUG", "FIELDS", key]
|
|
440
|
+
if path:
|
|
441
|
+
args.append(path)
|
|
442
|
+
|
|
443
|
+
return batch.custom_command(args)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
def debug_memory(
|
|
447
|
+
batch: TBatch,
|
|
448
|
+
key: TEncodable,
|
|
449
|
+
path: Optional[TEncodable] = None,
|
|
450
|
+
) -> TBatch:
|
|
451
|
+
"""
|
|
452
|
+
Reports memory usage in bytes of a JSON value at the specified `path` within the JSON document stored at `key`.
|
|
453
|
+
|
|
454
|
+
Args:
|
|
455
|
+
batch (TBatch): The batch to execute the command.
|
|
456
|
+
key (TEncodable): The key of the JSON document.
|
|
457
|
+
path (Optional[TEncodable]): The path within the JSON document. Defaults to None.
|
|
458
|
+
|
|
459
|
+
Command response:
|
|
460
|
+
Optional[TJsonUniversalResponse[int]]:
|
|
461
|
+
For JSONPath (`path` starts with `$`):
|
|
462
|
+
Returns an array of integers, indicating the memory usage in bytes of a JSON value for each matched `path`.
|
|
463
|
+
If `path` doesn't exist, an empty array will be returned.
|
|
464
|
+
For legacy path (`path` doesn't start with `$`):
|
|
465
|
+
Returns an integer, indicating the memory usage in bytes for the JSON value in `path`.
|
|
466
|
+
If multiple paths match, the memory usage of the first JSON value match is returned.
|
|
467
|
+
If `path` doesn't exist, an error is raised.
|
|
468
|
+
If `path` is not provided, it reports the total memory usage in bytes in the entire JSON document.
|
|
469
|
+
If `key` doesn't exist, None is returned.
|
|
470
|
+
"""
|
|
471
|
+
args = ["JSON.DEBUG", "MEMORY", key]
|
|
472
|
+
if path:
|
|
473
|
+
args.append(path)
|
|
474
|
+
|
|
475
|
+
return batch.custom_command(args)
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def delete(
|
|
479
|
+
batch: TBatch,
|
|
480
|
+
key: TEncodable,
|
|
481
|
+
path: Optional[TEncodable] = None,
|
|
482
|
+
) -> TBatch:
|
|
483
|
+
"""
|
|
484
|
+
Deletes the JSON value at the specified `path` within the JSON document stored at `key`.
|
|
485
|
+
|
|
486
|
+
Args:
|
|
487
|
+
batch (TBatch): The batch to execute the command.
|
|
488
|
+
key (TEncodable): The key of the JSON document.
|
|
489
|
+
path (Optional[TEncodable]): The path within the JSON document.
|
|
490
|
+
If None, deletes the entire JSON document at `key`. Defaults to None.
|
|
491
|
+
|
|
492
|
+
Command response:
|
|
493
|
+
int: The number of elements removed.
|
|
494
|
+
If `key` or `path` doesn't exist, returns 0.
|
|
495
|
+
"""
|
|
496
|
+
|
|
497
|
+
return batch.custom_command(["JSON.DEL", key] + ([path] if path else []))
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
def forget(
|
|
501
|
+
batch: TBatch,
|
|
502
|
+
key: TEncodable,
|
|
503
|
+
path: Optional[TEncodable] = None,
|
|
504
|
+
) -> TBatch:
|
|
505
|
+
"""
|
|
506
|
+
Deletes the JSON value at the specified `path` within the JSON document stored at `key`.
|
|
507
|
+
|
|
508
|
+
Args:
|
|
509
|
+
batch (TBatch): The batch to execute the command.
|
|
510
|
+
key (TEncodable): The key of the JSON document.
|
|
511
|
+
path (Optional[TEncodable]): The path within the JSON document.
|
|
512
|
+
If None, deletes the entire JSON document at `key`. Defaults to None.
|
|
513
|
+
|
|
514
|
+
Command response:
|
|
515
|
+
int: The number of elements removed.
|
|
516
|
+
If `key` or `path` doesn't exist, returns 0.
|
|
517
|
+
"""
|
|
518
|
+
|
|
519
|
+
return batch.custom_command(["JSON.FORGET", key] + ([path] if path else []))
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def numincrby(
|
|
523
|
+
batch: TBatch,
|
|
524
|
+
key: TEncodable,
|
|
525
|
+
path: TEncodable,
|
|
526
|
+
number: Union[int, float],
|
|
527
|
+
) -> TBatch:
|
|
528
|
+
"""
|
|
529
|
+
Increments or decrements the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.
|
|
530
|
+
|
|
531
|
+
Args:
|
|
532
|
+
batch (TBatch): The batch to execute the command.
|
|
533
|
+
key (TEncodable): The key of the JSON document.
|
|
534
|
+
path (TEncodable): The path within the JSON document.
|
|
535
|
+
number (Union[int, float]): The number to increment or decrement by.
|
|
536
|
+
|
|
537
|
+
Command response:
|
|
538
|
+
bytes:
|
|
539
|
+
For JSONPath (`path` starts with `$`):
|
|
540
|
+
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
541
|
+
incrementing for each matched `path`.
|
|
542
|
+
If a value is not a number, its corresponding return value will be `null`.
|
|
543
|
+
If `path` doesn't exist, a byte string representation of an empty array will be returned.
|
|
544
|
+
For legacy path (`path` doesn't start with `$`):
|
|
545
|
+
Returns a bytes string representation of the resulting value after the increment or decrement.
|
|
546
|
+
If multiple paths match, the result of the last updated value is returned.
|
|
547
|
+
If the value at the `path` is not a number or `path` doesn't exist, an error is raised.
|
|
548
|
+
If `key` does not exist, an error is raised.
|
|
549
|
+
If the result is out of the range of 64-bit IEEE double, an error is raised.
|
|
550
|
+
"""
|
|
551
|
+
args = ["JSON.NUMINCRBY", key, path, str(number)]
|
|
552
|
+
|
|
553
|
+
return batch.custom_command(args)
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
def nummultby(
|
|
557
|
+
batch: TBatch,
|
|
558
|
+
key: TEncodable,
|
|
559
|
+
path: TEncodable,
|
|
560
|
+
number: Union[int, float],
|
|
561
|
+
) -> TBatch:
|
|
562
|
+
"""
|
|
563
|
+
Multiplies the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.
|
|
564
|
+
|
|
565
|
+
Args:
|
|
566
|
+
batch (TBatch): The batch to execute the command.
|
|
567
|
+
key (TEncodable): The key of the JSON document.
|
|
568
|
+
path (TEncodable): The path within the JSON document.
|
|
569
|
+
number (Union[int, float]): The number to multiply by.
|
|
570
|
+
|
|
571
|
+
Command response:
|
|
572
|
+
bytes:
|
|
573
|
+
For JSONPath (`path` starts with `$`):
|
|
574
|
+
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
575
|
+
multiplication for each matched `path`.
|
|
576
|
+
If a value is not a number, its corresponding return value will be `null`.
|
|
577
|
+
If `path` doesn't exist, a byte string representation of an empty array will be returned.
|
|
578
|
+
For legacy path (`path` doesn't start with `$`):
|
|
579
|
+
Returns a bytes string representation of the resulting value after multiplication.
|
|
580
|
+
If multiple paths match, the result of the last updated value is returned.
|
|
581
|
+
If the value at the `path` is not a number or `path` doesn't exist, an error is raised.
|
|
582
|
+
If `key` does not exist, an error is raised.
|
|
583
|
+
If the result is out of the range of 64-bit IEEE double, an error is raised.
|
|
584
|
+
"""
|
|
585
|
+
args = ["JSON.NUMMULTBY", key, path, str(number)]
|
|
586
|
+
|
|
587
|
+
return batch.custom_command(args)
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def objlen(
|
|
591
|
+
batch: TBatch,
|
|
592
|
+
key: TEncodable,
|
|
593
|
+
path: Optional[TEncodable] = None,
|
|
594
|
+
) -> TBatch:
|
|
595
|
+
"""
|
|
596
|
+
Retrieves the number of key-value pairs in the object stored at the specified `path` within the JSON document stored at
|
|
597
|
+
`key`.
|
|
598
|
+
|
|
599
|
+
Args:
|
|
600
|
+
batch (TBatch): The batch to execute the command.
|
|
601
|
+
key (TEncodable): The key of the JSON document.
|
|
602
|
+
path (Optional[TEncodable]): The path within the JSON document. Defaults to None.
|
|
603
|
+
|
|
604
|
+
Command response:
|
|
605
|
+
Optional[TJsonResponse[int]]:
|
|
606
|
+
For JSONPath (`path` starts with `$`):
|
|
607
|
+
Returns a list of integer replies for every possible path, indicating the length of the object,
|
|
608
|
+
or None for JSON values matching the path that are not an object.
|
|
609
|
+
If `path` doesn't exist, an empty array will be returned.
|
|
610
|
+
For legacy path (`path` doesn't starts with `$`):
|
|
611
|
+
Returns the length of the object at `path`.
|
|
612
|
+
If multiple paths match, the length of the first object match is returned.
|
|
613
|
+
If the JSON value at `path` is not an object or if `path` doesn't exist, an error is raised.
|
|
614
|
+
If `key` doesn't exist, None is returned.
|
|
615
|
+
"""
|
|
616
|
+
args = ["JSON.OBJLEN", key]
|
|
617
|
+
if path:
|
|
618
|
+
args.append(path)
|
|
619
|
+
|
|
620
|
+
return batch.custom_command(args)
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
def objkeys(
|
|
624
|
+
batch: TBatch,
|
|
625
|
+
key: TEncodable,
|
|
626
|
+
path: Optional[TEncodable] = None,
|
|
627
|
+
) -> TBatch:
|
|
628
|
+
"""
|
|
629
|
+
Retrieves key names in the object values at the specified `path` within the JSON document stored at `key`.
|
|
630
|
+
|
|
631
|
+
Args:
|
|
632
|
+
batch (TBatch): The batch to execute the command.
|
|
633
|
+
key (TEncodable): The key of the JSON document.
|
|
634
|
+
path (Optional[TEncodable]): Represents the path within the JSON document where the key names will be retrieved.
|
|
635
|
+
Defaults to None.
|
|
636
|
+
|
|
637
|
+
Command response:
|
|
638
|
+
Optional[TJsonUniversalResponse[List[bytes]]]:
|
|
639
|
+
For JSONPath (`path` starts with `$`):
|
|
640
|
+
Returns a list of arrays containing key names for each matching object.
|
|
641
|
+
If a value matching the path is not an object, an empty array is returned.
|
|
642
|
+
If `path` doesn't exist, an empty array is returned.
|
|
643
|
+
For legacy path (`path` starts with `.`):
|
|
644
|
+
Returns a list of key names for the object value matching the path.
|
|
645
|
+
If multiple objects match the path, the key names of the first object are returned.
|
|
646
|
+
If a value matching the path is not an object, an error is raised.
|
|
647
|
+
If `path` doesn't exist, None is returned.
|
|
648
|
+
If `key` doesn't exist, None is returned.
|
|
649
|
+
"""
|
|
650
|
+
args = ["JSON.OBJKEYS", key]
|
|
651
|
+
if path:
|
|
652
|
+
args.append(path)
|
|
653
|
+
|
|
654
|
+
return batch.custom_command(args)
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
def resp(
|
|
658
|
+
batch: TBatch,
|
|
659
|
+
key: TEncodable,
|
|
660
|
+
path: Optional[TEncodable] = None,
|
|
661
|
+
) -> TBatch:
|
|
662
|
+
"""
|
|
663
|
+
Retrieve the JSON value at the specified `path` within the JSON document stored at `key`.
|
|
664
|
+
The returning result is in the Valkey or Redis OSS Serialization Protocol (RESP).\n
|
|
665
|
+
JSON null is mapped to the RESP Null Bulk String.\n
|
|
666
|
+
JSON Booleans are mapped to RESP Simple string.\n
|
|
667
|
+
JSON integers are mapped to RESP Integers.\n
|
|
668
|
+
JSON doubles are mapped to RESP Bulk Strings.\n
|
|
669
|
+
JSON strings are mapped to RESP Bulk Strings.\n
|
|
670
|
+
JSON arrays are represented as RESP arrays, where the first element is the simple string
|
|
671
|
+
[, followed by the array's elements.\n
|
|
672
|
+
JSON objects are represented as RESP object, where the first element is the simple string {, followed by key-value pairs,
|
|
673
|
+
each of which is a RESP bulk string.\n
|
|
674
|
+
|
|
675
|
+
Args:
|
|
676
|
+
batch (TBatch): The batch to execute the command.
|
|
677
|
+
key (TEncodable): The key of the JSON document.
|
|
678
|
+
path (Optional[TEncodable]): The path within the JSON document. Default to None.
|
|
679
|
+
|
|
680
|
+
Command response:
|
|
681
|
+
TJsonUniversalResponse[Optional[Union[bytes, int, List[Optional[Union[bytes, int]]]]]]
|
|
682
|
+
For JSONPath ('path' starts with '$'):
|
|
683
|
+
Returns a list of replies for every possible path, indicating the RESP form of the JSON value.
|
|
684
|
+
If `path` doesn't exist, returns an empty list.
|
|
685
|
+
For legacy path (`path` doesn't starts with `$`):
|
|
686
|
+
Returns a single reply for the JSON value at the specified path, in its RESP form.
|
|
687
|
+
This can be a bytes object, an integer, None, or a list representing complex structures.
|
|
688
|
+
If multiple paths match, the value of the first JSON value match is returned.
|
|
689
|
+
If `path` doesn't exist, an error is raised.
|
|
690
|
+
If `key` doesn't exist, an None is returned.
|
|
691
|
+
"""
|
|
692
|
+
args = ["JSON.RESP", key]
|
|
693
|
+
if path:
|
|
694
|
+
args.append(path)
|
|
695
|
+
|
|
696
|
+
return batch.custom_command(args)
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
def strappend(
|
|
700
|
+
batch: TBatch,
|
|
701
|
+
key: TEncodable,
|
|
702
|
+
value: TEncodable,
|
|
703
|
+
path: Optional[TEncodable] = None,
|
|
704
|
+
) -> TBatch:
|
|
705
|
+
"""
|
|
706
|
+
Appends the specified `value` to the string stored at the specified `path` within the JSON document stored at `key`.
|
|
707
|
+
|
|
708
|
+
Args:
|
|
709
|
+
batch (TBatch): The batch to execute the command.
|
|
710
|
+
key (TEncodable): The key of the JSON document.
|
|
711
|
+
value (TEncodable): The value to append to the string. Must be wrapped with single quotes. For example,
|
|
712
|
+
to append "foo", pass '"foo"'.
|
|
713
|
+
path (Optional[TEncodable]): The path within the JSON document. Default to None.
|
|
714
|
+
|
|
715
|
+
Command response:
|
|
716
|
+
TJsonResponse[int]:
|
|
717
|
+
For JSONPath (`path` starts with `$`):
|
|
718
|
+
Returns a list of integer replies for every possible path, indicating the length of the resulting string after
|
|
719
|
+
appending `value`,
|
|
720
|
+
or None for JSON values matching the path that are not string.
|
|
721
|
+
If `key` doesn't exist, an error is raised.
|
|
722
|
+
For legacy path (`path` doesn't start with `$`):
|
|
723
|
+
Returns the length of the resulting string after appending `value` to the string at `path`.
|
|
724
|
+
If multiple paths match, the length of the last updated string is returned.
|
|
725
|
+
If the JSON value at `path` is not a string of if `path` doesn't exist, an error is raised.
|
|
726
|
+
If `key` doesn't exist, an error is raised.
|
|
727
|
+
For more information about the returned type, see `TJsonResponse`.
|
|
728
|
+
"""
|
|
729
|
+
return batch.custom_command(
|
|
730
|
+
["JSON.STRAPPEND", key] + ([path, value] if path else [value])
|
|
731
|
+
)
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def strlen(
|
|
735
|
+
batch: TBatch,
|
|
736
|
+
key: TEncodable,
|
|
737
|
+
path: Optional[TEncodable] = None,
|
|
738
|
+
) -> TBatch:
|
|
739
|
+
"""
|
|
740
|
+
Returns the length of the JSON string value stored at the specified `path` within the JSON document stored at `key`.
|
|
741
|
+
|
|
742
|
+
Args:
|
|
743
|
+
batch (TBatch): The batch to execute the command.
|
|
744
|
+
key (TEncodable): The key of the JSON document.
|
|
745
|
+
path (Optional[TEncodable]): The path within the JSON document. Default to None.
|
|
746
|
+
|
|
747
|
+
Command response:
|
|
748
|
+
TJsonResponse[Optional[int]]:
|
|
749
|
+
For JSONPath (`path` starts with `$`):
|
|
750
|
+
Returns a list of integer replies for every possible path, indicating the length of the JSON string value,
|
|
751
|
+
or None for JSON values matching the path that are not string.
|
|
752
|
+
For legacy path (`path` doesn't start with `$`):
|
|
753
|
+
Returns the length of the JSON value at `path` or None if `key` doesn't exist.
|
|
754
|
+
If multiple paths match, the length of the first mached string is returned.
|
|
755
|
+
If the JSON value at `path` is not a string of if `path` doesn't exist, an error is raised.
|
|
756
|
+
If `key` doesn't exist, None is returned.
|
|
757
|
+
For more information about the returned type, see `TJsonResponse`.
|
|
758
|
+
"""
|
|
759
|
+
return batch.custom_command(
|
|
760
|
+
["JSON.STRLEN", key, path] if path else ["JSON.STRLEN", key]
|
|
761
|
+
)
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
def toggle(
|
|
765
|
+
batch: TBatch,
|
|
766
|
+
key: TEncodable,
|
|
767
|
+
path: TEncodable,
|
|
768
|
+
) -> TBatch:
|
|
769
|
+
"""
|
|
770
|
+
Toggles a Boolean value stored at the specified `path` within the JSON document stored at `key`.
|
|
771
|
+
|
|
772
|
+
Args:
|
|
773
|
+
batch (TBatch): The batch to execute the command.
|
|
774
|
+
key (TEncodable): The key of the JSON document.
|
|
775
|
+
path (TEncodable): The path within the JSON document. Default to None.
|
|
776
|
+
|
|
777
|
+
Command response:
|
|
778
|
+
TJsonResponse[bool]:
|
|
779
|
+
For JSONPath (`path` starts with `$`):
|
|
780
|
+
Returns a list of boolean replies for every possible path, with the toggled boolean value,
|
|
781
|
+
or None for JSON values matching the path that are not boolean.
|
|
782
|
+
If `key` doesn't exist, an error is raised.
|
|
783
|
+
For legacy path (`path` doesn't start with `$`):
|
|
784
|
+
Returns the value of the toggled boolean in `path`.
|
|
785
|
+
If the JSON value at `path` is not a boolean of if `path` doesn't exist, an error is raised.
|
|
786
|
+
If `key` doesn't exist, an error is raised.
|
|
787
|
+
For more information about the returned type, see `TJsonResponse`.
|
|
788
|
+
"""
|
|
789
|
+
return batch.custom_command(["JSON.TOGGLE", key, path])
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
def type(
|
|
793
|
+
batch: TBatch,
|
|
794
|
+
key: TEncodable,
|
|
795
|
+
path: Optional[TEncodable] = None,
|
|
796
|
+
) -> TBatch:
|
|
797
|
+
"""
|
|
798
|
+
Retrieves the type of the JSON value at the specified `path` within the JSON document stored at `key`.
|
|
799
|
+
|
|
800
|
+
Args:
|
|
801
|
+
batch (TBatch): The batch to execute the command.
|
|
802
|
+
key (TEncodable): The key of the JSON document.
|
|
803
|
+
path (Optional[TEncodable]): The path within the JSON document. Default to None.
|
|
804
|
+
|
|
805
|
+
Command response:
|
|
806
|
+
Optional[TJsonUniversalResponse[bytes]]:
|
|
807
|
+
For JSONPath ('path' starts with '$'):
|
|
808
|
+
Returns a list of byte string replies for every possible path, indicating the type of the JSON value.
|
|
809
|
+
If `path` doesn't exist, an empty array will be returned.
|
|
810
|
+
For legacy path (`path` doesn't starts with `$`):
|
|
811
|
+
Returns the type of the JSON value at `path`.
|
|
812
|
+
If multiple paths match, the type of the first JSON value match is returned.
|
|
813
|
+
If `path` doesn't exist, None will be returned.
|
|
814
|
+
If `key` doesn't exist, None is returned.
|
|
815
|
+
"""
|
|
816
|
+
args = ["JSON.TYPE", key]
|
|
817
|
+
if path:
|
|
818
|
+
args.append(path)
|
|
819
|
+
|
|
820
|
+
return batch.custom_command(args)
|