valkey-glide 1.3.5__cp39-cp39-macosx_11_0_arm64.whl → 2.2.2__cp39-cp39-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.
- glide/__init__.py +165 -107
- glide/async_commands/cluster_commands.py +318 -136
- glide/async_commands/core.py +1770 -992
- glide/async_commands/{server_modules/ft.py → ft.py} +91 -21
- glide/async_commands/{server_modules/glide_json.py → glide_json.py} +148 -134
- glide/async_commands/standalone_commands.py +203 -137
- glide/glide.cpython-39-darwin.so +0 -0
- glide/glide.pyi +26 -1
- glide/glide_client.py +352 -135
- glide/logger.py +34 -22
- glide/opentelemetry.py +185 -0
- glide_shared/__init__.py +330 -0
- glide_shared/commands/__init__.py +0 -0
- glide/async_commands/transaction.py → glide_shared/commands/batch.py +1839 -1017
- glide_shared/commands/batch_options.py +261 -0
- {glide/async_commands → glide_shared/commands}/bitmap.py +94 -85
- {glide/async_commands → glide_shared/commands}/command_args.py +7 -6
- glide_shared/commands/core_options.py +407 -0
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +18 -11
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +27 -13
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +16 -11
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +16 -8
- {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +160 -130
- glide_shared/commands/server_modules/json_options.py +93 -0
- {glide/async_commands → glide_shared/commands}/sorted_set.py +41 -31
- {glide/async_commands → glide_shared/commands}/stream.py +95 -88
- glide_shared/config.py +975 -0
- {glide → glide_shared}/constants.py +11 -7
- {glide → glide_shared}/exceptions.py +27 -1
- glide_shared/protobuf/command_request_pb2.py +56 -0
- glide_shared/protobuf/connection_request_pb2.py +56 -0
- {glide → glide_shared}/protobuf/response_pb2.py +6 -6
- {glide → glide_shared}/protobuf_codec.py +7 -6
- glide_shared/routes.py +161 -0
- valkey_glide-2.2.2.dist-info/METADATA +211 -0
- valkey_glide-2.2.2.dist-info/RECORD +40 -0
- glide/config.py +0 -590
- glide/protobuf/command_request_pb2.py +0 -54
- glide/protobuf/command_request_pb2.pyi +0 -1164
- glide/protobuf/connection_request_pb2.py +0 -52
- glide/protobuf/connection_request_pb2.pyi +0 -292
- glide/protobuf/response_pb2.pyi +0 -101
- glide/routes.py +0 -114
- valkey_glide-1.3.5.dist-info/METADATA +0 -125
- valkey_glide-1.3.5.dist-info/RECORD +0 -37
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
- {valkey_glide-1.3.5.dist-info → valkey_glide-2.2.2.dist-info}/WHEEL +0 -0
|
@@ -7,9 +7,10 @@ Examples:
|
|
|
7
7
|
>>> import json
|
|
8
8
|
>>> value = {'a': 1.0, 'b': 2}
|
|
9
9
|
>>> json_str = json.dumps(value) # Convert Python dictionary to JSON string using json.dumps()
|
|
10
|
-
>>> await
|
|
10
|
+
>>> await glide_json.set(client, "doc", "$", json_str)
|
|
11
11
|
'OK' # Indicates successful setting of the value at path '$' in the key stored at `doc`.
|
|
12
|
-
>>> json_get = await glide_json.get(client, "doc", "$") # Returns the value at path '$' in the JSON document stored at
|
|
12
|
+
>>> json_get = await glide_json.get(client, "doc", "$") # Returns the value at path '$' in the JSON document stored at
|
|
13
|
+
# `doc` as JSON string.
|
|
13
14
|
>>> print(json_get)
|
|
14
15
|
b"[{\"a\":1.0,\"b\":2}]"
|
|
15
16
|
>>> json.loads(str(json_get))
|
|
@@ -18,98 +19,20 @@ Examples:
|
|
|
18
19
|
"""
|
|
19
20
|
from typing import List, Optional, Union, cast
|
|
20
21
|
|
|
21
|
-
from
|
|
22
|
-
from
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
from glide_shared.commands.core_options import ConditionalChange
|
|
23
|
+
from glide_shared.commands.server_modules.json_options import (
|
|
24
|
+
JsonArrIndexOptions,
|
|
25
|
+
JsonArrPopOptions,
|
|
26
|
+
JsonGetOptions,
|
|
27
|
+
)
|
|
28
|
+
from glide_shared.constants import (
|
|
29
|
+
TOK,
|
|
30
|
+
TEncodable,
|
|
31
|
+
TJsonResponse,
|
|
32
|
+
TJsonUniversalResponse,
|
|
33
|
+
)
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
class JsonGetOptions:
|
|
28
|
-
"""
|
|
29
|
-
Represents options for formatting JSON data, to be used in the [JSON.GET](https://valkey.io/commands/json.get/) command.
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
indent (Optional[str]): Sets an indentation string for nested levels. Defaults to None.
|
|
33
|
-
newline (Optional[str]): Sets a string that's printed at the end of each line. Defaults to None.
|
|
34
|
-
space (Optional[str]): Sets a string that's put between a key and a value. Defaults to None.
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
def __init__(
|
|
38
|
-
self,
|
|
39
|
-
indent: Optional[str] = None,
|
|
40
|
-
newline: Optional[str] = None,
|
|
41
|
-
space: Optional[str] = None,
|
|
42
|
-
):
|
|
43
|
-
self.indent = indent
|
|
44
|
-
self.new_line = newline
|
|
45
|
-
self.space = space
|
|
46
|
-
|
|
47
|
-
def get_options(self) -> List[str]:
|
|
48
|
-
args = []
|
|
49
|
-
if self.indent:
|
|
50
|
-
args.extend(["INDENT", self.indent])
|
|
51
|
-
if self.new_line:
|
|
52
|
-
args.extend(["NEWLINE", self.new_line])
|
|
53
|
-
if self.space:
|
|
54
|
-
args.extend(["SPACE", self.space])
|
|
55
|
-
return args
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class JsonArrIndexOptions:
|
|
59
|
-
"""
|
|
60
|
-
Options for the `JSON.ARRINDEX` command.
|
|
61
|
-
|
|
62
|
-
Args:
|
|
63
|
-
start (int): The inclusive start index from which the search begins. Defaults to None.
|
|
64
|
-
end (Optional[int]): The exclusive end index where the search stops. Defaults to None.
|
|
65
|
-
|
|
66
|
-
Note:
|
|
67
|
-
- If `start` is greater than `end`, the command returns `-1` to indicate that the value was not found.
|
|
68
|
-
- Indices that exceed the array bounds are automatically adjusted to the nearest valid position.
|
|
69
|
-
"""
|
|
70
|
-
|
|
71
|
-
def __init__(self, start: int, end: Optional[int] = None):
|
|
72
|
-
self.start = start
|
|
73
|
-
self.end = end
|
|
74
|
-
|
|
75
|
-
def to_args(self) -> List[str]:
|
|
76
|
-
"""
|
|
77
|
-
Get the options as a list of arguments for the JSON.ARRINDEX command.
|
|
78
|
-
|
|
79
|
-
Returns:
|
|
80
|
-
List[str]: A list containing the start and end indices if specified.
|
|
81
|
-
"""
|
|
82
|
-
args = [str(self.start)]
|
|
83
|
-
if self.end is not None:
|
|
84
|
-
args.append(str(self.end))
|
|
85
|
-
return args
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
class JsonArrPopOptions:
|
|
89
|
-
"""
|
|
90
|
-
Options for the JSON.ARRPOP command.
|
|
91
|
-
|
|
92
|
-
Args:
|
|
93
|
-
path (TEncodable): The path within the JSON document.
|
|
94
|
-
index (Optional[int]): The index of the element to pop. If not specified, will pop the last element.
|
|
95
|
-
Out of boundary indexes are rounded to their respective array boundaries. Defaults to None.
|
|
96
|
-
"""
|
|
97
|
-
|
|
98
|
-
def __init__(self, path: TEncodable, index: Optional[int] = None):
|
|
99
|
-
self.path = path
|
|
100
|
-
self.index = index
|
|
101
|
-
|
|
102
|
-
def to_args(self) -> List[TEncodable]:
|
|
103
|
-
"""
|
|
104
|
-
Get the options as a list of arguments for the `JSON.ARRPOP` command.
|
|
105
|
-
|
|
106
|
-
Returns:
|
|
107
|
-
List[TEncodable]: A list containing the path and, if specified, the index.
|
|
108
|
-
"""
|
|
109
|
-
args = [self.path]
|
|
110
|
-
if self.index is not None:
|
|
111
|
-
args.append(str(self.index))
|
|
112
|
-
return args
|
|
35
|
+
from ..glide_client import TGlideClient
|
|
113
36
|
|
|
114
37
|
|
|
115
38
|
async def set(
|
|
@@ -126,7 +49,8 @@ async def set(
|
|
|
126
49
|
client (TGlideClient): The client to execute the command.
|
|
127
50
|
key (TEncodable): The key of the JSON document.
|
|
128
51
|
path (TEncodable): Represents the path within the JSON document where the value will be set.
|
|
129
|
-
The key will be modified only if `value` is added as the last child in the specified `path`, or if the specified
|
|
52
|
+
The key will be modified only if `value` is added as the last child in the specified `path`, or if the specified
|
|
53
|
+
`path` acts as the parent of a new child being added.
|
|
130
54
|
value (TEncodable): The value to set at the specific path, in JSON formatted bytes or str.
|
|
131
55
|
set_condition (Optional[ConditionalChange]): Set the value only if the given condition is met (within the key or path).
|
|
132
56
|
Equivalent to [`XX` | `NX`] in the RESP API. Defaults to None.
|
|
@@ -162,8 +86,10 @@ async def get(
|
|
|
162
86
|
Args:
|
|
163
87
|
client (TGlideClient): The client to execute the command.
|
|
164
88
|
key (TEncodable): The key of the JSON document.
|
|
165
|
-
paths (Optional[Union[TEncodable, List[TEncodable]]]): The path or list of paths within the JSON document.
|
|
166
|
-
|
|
89
|
+
paths (Optional[Union[TEncodable, List[TEncodable]]]): The path or list of paths within the JSON document.
|
|
90
|
+
Default to None.
|
|
91
|
+
options (Optional[JsonGetOptions]): Options for formatting the byte representation of the JSON data.
|
|
92
|
+
See `JsonGetOptions`.
|
|
167
93
|
|
|
168
94
|
Returns:
|
|
169
95
|
TJsonResponse[Optional[bytes]]:
|
|
@@ -177,8 +103,10 @@ async def get(
|
|
|
177
103
|
If `path` doesn't exist, an error is raised.
|
|
178
104
|
If `key` doesn't exist, returns None.
|
|
179
105
|
If multiple paths are given:
|
|
180
|
-
Returns a stringified JSON object in bytes, in which each path is a key, and it's corresponding value, is the
|
|
181
|
-
|
|
106
|
+
Returns a stringified JSON object in bytes, in which each path is a key, and it's corresponding value, is the
|
|
107
|
+
value as if the path was executed in the command as a single path.
|
|
108
|
+
In case of multiple paths, and `paths` are a mix of both JSONPath and legacy path, the command behaves as if all are
|
|
109
|
+
JSONPath paths.
|
|
182
110
|
For more information about the returned type, see `TJsonResponse`.
|
|
183
111
|
|
|
184
112
|
Examples:
|
|
@@ -190,9 +118,12 @@ async def get(
|
|
|
190
118
|
>>> await glide_json.get(client, "doc", "$")
|
|
191
119
|
b"[{\"a\":1.0,\"b\":2}]" # Returns the value at path '$' in the JSON document stored at `doc`.
|
|
192
120
|
>>> await glide_json.get(client, "doc", ["$.a", "$.b"], JsonGetOptions(indent=" ", newline="\n", space=" "))
|
|
193
|
-
b"{\n \"$.a\": [\n 1.0\n ],\n \"$.b\": [\n 2\n ]\n}" # Returns the values at paths '$.a' and '$.b' in the JSON
|
|
121
|
+
b"{\n \"$.a\": [\n 1.0\n ],\n \"$.b\": [\n 2\n ]\n}" # Returns the values at paths '$.a' and '$.b' in the JSON
|
|
122
|
+
# document stored at `doc`, with specified
|
|
123
|
+
# formatting options.
|
|
194
124
|
>>> await glide_json.get(client, "doc", "$.non_existing_path")
|
|
195
|
-
b"[]" # Returns an empty array since the path '$.non_existing_path' does not exist in the JSON document
|
|
125
|
+
b"[]" # Returns an empty array since the path '$.non_existing_path' does not exist in the JSON document
|
|
126
|
+
# stored at `doc`.
|
|
196
127
|
"""
|
|
197
128
|
args = ["JSON.GET", key]
|
|
198
129
|
if options:
|
|
@@ -224,7 +155,8 @@ async def arrappend(
|
|
|
224
155
|
Returns:
|
|
225
156
|
TJsonResponse[int]:
|
|
226
157
|
For JSONPath (`path` starts with `$`):
|
|
227
|
-
Returns a list of integer replies for every possible path, indicating the new length of the array after
|
|
158
|
+
Returns a list of integer replies for every possible path, indicating the new length of the array after
|
|
159
|
+
appending `values`,
|
|
228
160
|
or None for JSON values matching the path that are not an array.
|
|
229
161
|
If `path` doesn't exist, an empty array will be returned.
|
|
230
162
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -258,12 +190,14 @@ async def arrindex(
|
|
|
258
190
|
options: Optional[JsonArrIndexOptions] = None,
|
|
259
191
|
) -> TJsonResponse[int]:
|
|
260
192
|
"""
|
|
261
|
-
Searches for the first occurrence of a scalar JSON value (i.e., a value that is neither an object nor an array) within
|
|
193
|
+
Searches for the first occurrence of a scalar JSON value (i.e., a value that is neither an object nor an array) within
|
|
194
|
+
arrays at the specified `path` in the JSON document stored at `key`.
|
|
262
195
|
|
|
263
196
|
If specified, `options.start` and `options.end` define an inclusive-to-exclusive search range within the array.
|
|
264
197
|
(Where `options.start` is inclusive and `options.end` is exclusive).
|
|
265
198
|
|
|
266
|
-
Out-of-range indices adjust to the nearest valid position, and negative values count from the end (e.g., `-1` is the last
|
|
199
|
+
Out-of-range indices adjust to the nearest valid position, and negative values count from the end (e.g., `-1` is the last
|
|
200
|
+
element, `-2` the second last).
|
|
267
201
|
|
|
268
202
|
Setting `options.end` to `0` behaves like `-1`, extending the range to the array's end (inclusive).
|
|
269
203
|
|
|
@@ -274,18 +208,21 @@ async def arrindex(
|
|
|
274
208
|
key (TEncodable): The key of the JSON document.
|
|
275
209
|
path (TEncodable): The path within the JSON document.
|
|
276
210
|
value (TEncodable): The value to search for within the arrays.
|
|
277
|
-
options (Optional[JsonArrIndexOptions]): Options specifying an inclusive `start` index and an optional exclusive `end`
|
|
211
|
+
options (Optional[JsonArrIndexOptions]): Options specifying an inclusive `start` index and an optional exclusive `end`
|
|
212
|
+
index for a range-limited search.
|
|
278
213
|
Defaults to the full array if not provided. See `JsonArrIndexOptions`.
|
|
279
214
|
|
|
280
215
|
Returns:
|
|
281
216
|
Optional[TJsonResponse[int]]:
|
|
282
217
|
For JSONPath (`path` starts with `$`):
|
|
283
|
-
Returns an array of integers for every possible path, indicating of the first occurrence of `value`
|
|
218
|
+
Returns an array of integers for every possible path, indicating of the first occurrence of `value`
|
|
219
|
+
within the array,
|
|
284
220
|
or None for JSON values matching the path that are not an array.
|
|
285
221
|
A returned value of `-1` indicates that the value was not found in that particular array.
|
|
286
222
|
If `path` does not exist, an empty array will be returned.
|
|
287
223
|
For legacy path (`path` doesn't start with `$`):
|
|
288
|
-
Returns an integer representing the index of the first occurrence of `value` within the array at the
|
|
224
|
+
Returns an integer representing the index of the first occurrence of `value` within the array at the
|
|
225
|
+
specified path.
|
|
289
226
|
A returned value of `-1` indicates that the value was not found in that particular array.
|
|
290
227
|
If multiple paths match, the index of the value from the first matching array is returned.
|
|
291
228
|
If the JSON value at the `path` is not an array or if `path` does not exist, an error is raised.
|
|
@@ -331,7 +268,8 @@ async def arrinsert(
|
|
|
331
268
|
values: List[TEncodable],
|
|
332
269
|
) -> TJsonResponse[int]:
|
|
333
270
|
"""
|
|
334
|
-
Inserts one or more values into the array at the specified `path` within the JSON document stored at `key`,
|
|
271
|
+
Inserts one or more values into the array at the specified `path` within the JSON document stored at `key`,
|
|
272
|
+
before the given `index`.
|
|
335
273
|
|
|
336
274
|
Args:
|
|
337
275
|
client (TGlideClient): The client to execute the command.
|
|
@@ -442,7 +380,8 @@ async def arrpop(
|
|
|
442
380
|
Args:
|
|
443
381
|
client (TGlideClient): The client to execute the command.
|
|
444
382
|
key (TEncodable): The key of the JSON document.
|
|
445
|
-
options (Optional[JsonArrPopOptions]): Options including the path and optional index. See `JsonArrPopOptions`.
|
|
383
|
+
options (Optional[JsonArrPopOptions]): Options including the path and optional index. See `JsonArrPopOptions`.
|
|
384
|
+
Default to None.
|
|
446
385
|
If not specified, attempts to pop the last element from the root value if it's an array.
|
|
447
386
|
If the root value is not an array, an error will be raised.
|
|
448
387
|
|
|
@@ -461,7 +400,12 @@ async def arrpop(
|
|
|
461
400
|
|
|
462
401
|
Examples:
|
|
463
402
|
>>> from glide import glide_json
|
|
464
|
-
>>> await glide_json.set(
|
|
403
|
+
>>> await glide_json.set(
|
|
404
|
+
... client,
|
|
405
|
+
... "doc",
|
|
406
|
+
... "$",
|
|
407
|
+
... '{"a": [1, 2, true], "b": {"a": [3, 4, ["value", 3, false], 5], "c": {"a": 42}}}'
|
|
408
|
+
... )
|
|
465
409
|
b'OK'
|
|
466
410
|
>>> await glide_json.arrpop(client, "doc", JsonArrPopOptions(path="$.a", index=1))
|
|
467
411
|
[b'2'] # Pop second element from array at path $.a
|
|
@@ -501,7 +445,8 @@ async def arrtrim(
|
|
|
501
445
|
end: int,
|
|
502
446
|
) -> TJsonResponse[int]:
|
|
503
447
|
"""
|
|
504
|
-
Trims an array at the specified `path` within the JSON document stored at `key` so that it becomes a subarray [start, end],
|
|
448
|
+
Trims an array at the specified `path` within the JSON document stored at `key` so that it becomes a subarray [start, end],
|
|
449
|
+
both inclusive.
|
|
505
450
|
If `start` < 0, it is treated as 0.
|
|
506
451
|
If `end` >= size (size of the array), it is treated as size-1.
|
|
507
452
|
If `start` >= size or `start` > `end`, the array is emptied and 0 is returned.
|
|
@@ -516,7 +461,8 @@ async def arrtrim(
|
|
|
516
461
|
Returns:
|
|
517
462
|
TJsonResponse[int]:
|
|
518
463
|
For JSONPath (`path` starts with '$'):
|
|
519
|
-
Returns a list of integer replies for every possible path, indicating the new length of the array, or None for
|
|
464
|
+
Returns a list of integer replies for every possible path, indicating the new length of the array, or None for
|
|
465
|
+
JSON values matching the path that are not an array.
|
|
520
466
|
If a value is an empty array, its corresponding return value is 0.
|
|
521
467
|
If `path` doesn't exist, an empty array will be returned.
|
|
522
468
|
For legacy path (`path` doesn't starts with `$`):
|
|
@@ -566,12 +512,18 @@ async def clear(
|
|
|
566
512
|
Returns:
|
|
567
513
|
int: The number of containers cleared, numeric values zeroed, and booleans toggled to `false`,
|
|
568
514
|
and string values converted to empty strings.
|
|
569
|
-
If `path` doesn't exist, or the value at `path` is already empty (e.g., an empty array, object, or string),
|
|
515
|
+
If `path` doesn't exist, or the value at `path` is already empty (e.g., an empty array, object, or string),
|
|
516
|
+
0 is returned.
|
|
570
517
|
If `key doesn't exist, an error is raised.
|
|
571
518
|
|
|
572
519
|
Examples:
|
|
573
520
|
>>> from glide import glide_json
|
|
574
|
-
>>> await glide_json.set(
|
|
521
|
+
>>> await glide_json.set(
|
|
522
|
+
... client,
|
|
523
|
+
... "doc",
|
|
524
|
+
... "$",
|
|
525
|
+
... '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14, "nullVal": null}'
|
|
526
|
+
... )
|
|
575
527
|
'OK' # JSON document is successfully set.
|
|
576
528
|
>>> await glide_json.clear(client, "doc", "$.*")
|
|
577
529
|
6 # 6 values are cleared (arrays/objects/strings/numbers/booleans), but `null` remains as is.
|
|
@@ -580,7 +532,18 @@ async def clear(
|
|
|
580
532
|
>>> await glide_json.clear(client, "doc", "$.*")
|
|
581
533
|
0 # No further clearing needed since the containers are already empty and the values are defaults.
|
|
582
534
|
|
|
583
|
-
>>> await glide_json.set(
|
|
535
|
+
>>> await glide_json.set(
|
|
536
|
+
... client,
|
|
537
|
+
... "doc",
|
|
538
|
+
... "$",
|
|
539
|
+
... (
|
|
540
|
+
... '{"a": 1, '
|
|
541
|
+
... '"b": {"a": [5, 6, 7], "b": {"a": true}}, '
|
|
542
|
+
... '"c": {"a": "value", "b": {"a": 3.5}}, '
|
|
543
|
+
... '"d": {"a": {"foo": "foo"}}, '
|
|
544
|
+
... '"nullVal": null}'
|
|
545
|
+
... )
|
|
546
|
+
... )
|
|
584
547
|
'OK'
|
|
585
548
|
>>> await glide_json.clear(client, "doc", "b.a[1:3]")
|
|
586
549
|
2 # 2 elements (`6` and `7`) are cleared.
|
|
@@ -609,7 +572,8 @@ async def debug_fields(
|
|
|
609
572
|
"""
|
|
610
573
|
Returns the number of fields of the JSON value at the specified `path` within the JSON document stored at `key`.
|
|
611
574
|
- **Primitive Values**: Each non-container JSON value (e.g., strings, numbers, booleans, and null) counts as one field.
|
|
612
|
-
- **Arrays and Objects:**: Each item in an array and each key-value pair in an object is counted as one field.
|
|
575
|
+
- **Arrays and Objects:**: Each item in an array and each key-value pair in an object is counted as one field.
|
|
576
|
+
(Each top-level value counts as one field, regardless of it's type.)
|
|
613
577
|
- Their nested values are counted recursively and added to the total.
|
|
614
578
|
- **Example**: For the JSON `{"a": 1, "b": [2, 3, {"c": 4}]}`, the count would be:
|
|
615
579
|
- Top-level: 2 fields (`"a"` and `"b"`)
|
|
@@ -643,7 +607,22 @@ async def debug_fields(
|
|
|
643
607
|
>>> await glide_json.debug_fields(client, "k1", ".")
|
|
644
608
|
14 # 9 top-level fields + 5 nested address fields
|
|
645
609
|
|
|
646
|
-
>>> await glide_json.set(
|
|
610
|
+
>>> await glide_json.set(
|
|
611
|
+
... client,
|
|
612
|
+
... "k1",
|
|
613
|
+
... "$",
|
|
614
|
+
... (
|
|
615
|
+
... '{"firstName":"John", '
|
|
616
|
+
... '"lastName":"Smith", '
|
|
617
|
+
... '"age":27, '
|
|
618
|
+
... '"weight":135.25, '
|
|
619
|
+
... '"isAlive":true, '
|
|
620
|
+
... '"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"}, '
|
|
621
|
+
... '"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}], '
|
|
622
|
+
... '"children":[], '
|
|
623
|
+
... '"spouse":null}'
|
|
624
|
+
... )
|
|
625
|
+
... )
|
|
647
626
|
'OK'
|
|
648
627
|
>>> await glide_json.debug_fields(client, "k1")
|
|
649
628
|
19
|
|
@@ -692,7 +671,22 @@ async def debug_memory(
|
|
|
692
671
|
>>> await glide_json.debug_memory(client, "k1", "$[*]")
|
|
693
672
|
[16, 16, 19, 16, 16, 16, 16, 66, 64]
|
|
694
673
|
|
|
695
|
-
>>> await glide_json.set(
|
|
674
|
+
>>> await glide_json.set(
|
|
675
|
+
... client,
|
|
676
|
+
... "k1",
|
|
677
|
+
... "$",
|
|
678
|
+
... (
|
|
679
|
+
... '{"firstName":"John", '
|
|
680
|
+
... '"lastName":"Smith", '
|
|
681
|
+
... '"age":27, '
|
|
682
|
+
... '"weight":135.25, '
|
|
683
|
+
... '"isAlive":true, '
|
|
684
|
+
... '"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"}, '
|
|
685
|
+
... '"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}], '
|
|
686
|
+
... '"children":[], '
|
|
687
|
+
... '"spouse":null}'
|
|
688
|
+
... )
|
|
689
|
+
... )
|
|
696
690
|
'OK'
|
|
697
691
|
>>> await glide_json.debug_memory(client, "k1")
|
|
698
692
|
472
|
|
@@ -816,14 +810,16 @@ async def mget(
|
|
|
816
810
|
>>> import json
|
|
817
811
|
>>> json_strs = await glide_json.mget(client, ["doc1", "doc2"], "$")
|
|
818
812
|
>>> [json.loads(js) for js in json_strs] # Parse JSON strings to Python data
|
|
819
|
-
[[{"a": 1.0, "b": 2}], [{"a": 2.0, "b": {"a": 3.0, "b" : 4.0}}]] # JSON objects retrieved from keys
|
|
813
|
+
[[{"a": 1.0, "b": 2}], [{"a": 2.0, "b": {"a": 3.0, "b" : 4.0}}]] # JSON objects retrieved from keys
|
|
814
|
+
# `doc1` and `doc2`
|
|
820
815
|
>>> await glide_json.mget(client, ["doc1", "doc2"], "$.a")
|
|
821
816
|
[b"[1.0]", b"[2.0]"] # Returns values at path '$.a' for the JSON documents stored at `doc1` and `doc2`.
|
|
822
817
|
>>> await glide_json.mget(client, ["doc1"], "$.non_existing_path")
|
|
823
|
-
[None] # Returns an empty array since the path '$.non_existing_path' does not exist in the JSON document
|
|
818
|
+
[None] # Returns an empty array since the path '$.non_existing_path' does not exist in the JSON document
|
|
819
|
+
# stored at `doc1`.
|
|
824
820
|
"""
|
|
825
821
|
args = ["JSON.MGET"] + keys + [path]
|
|
826
|
-
return cast(
|
|
822
|
+
return cast(List[Optional[bytes]], await client.custom_command(args))
|
|
827
823
|
|
|
828
824
|
|
|
829
825
|
async def numincrby(
|
|
@@ -844,7 +840,8 @@ async def numincrby(
|
|
|
844
840
|
Returns:
|
|
845
841
|
bytes:
|
|
846
842
|
For JSONPath (`path` starts with `$`):
|
|
847
|
-
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
843
|
+
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
844
|
+
incrementing for each matched `path`.
|
|
848
845
|
If a value is not a number, its corresponding return value will be `null`.
|
|
849
846
|
If `path` doesn't exist, a byte string representation of an empty array will be returned.
|
|
850
847
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -886,7 +883,8 @@ async def nummultby(
|
|
|
886
883
|
Returns:
|
|
887
884
|
bytes:
|
|
888
885
|
For JSONPath (`path` starts with `$`):
|
|
889
|
-
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
886
|
+
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
887
|
+
multiplication for each matched `path`.
|
|
890
888
|
If a value is not a number, its corresponding return value will be `null`.
|
|
891
889
|
If `path` doesn't exist, a byte string representation of an empty array will be returned.
|
|
892
890
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -916,7 +914,8 @@ async def objlen(
|
|
|
916
914
|
path: Optional[TEncodable] = None,
|
|
917
915
|
) -> Optional[TJsonResponse[int]]:
|
|
918
916
|
"""
|
|
919
|
-
Retrieves the number of key-value pairs in the object stored at the specified `path` within the JSON document stored at
|
|
917
|
+
Retrieves the number of key-value pairs in the object stored at the specified `path` within the JSON document stored at
|
|
918
|
+
`key`.
|
|
920
919
|
|
|
921
920
|
Args:
|
|
922
921
|
client (TGlideClient): The client to execute the command.
|
|
@@ -1026,8 +1025,10 @@ async def resp(
|
|
|
1026
1025
|
JSON integers are mapped to RESP Integers.\n
|
|
1027
1026
|
JSON doubles are mapped to RESP Bulk Strings.\n
|
|
1028
1027
|
JSON strings are mapped to RESP Bulk Strings.\n
|
|
1029
|
-
JSON arrays are represented as RESP arrays, where the first element is the simple string [, followed by the array's
|
|
1030
|
-
|
|
1028
|
+
JSON arrays are represented as RESP arrays, where the first element is the simple string [, followed by the array's
|
|
1029
|
+
elements.\n
|
|
1030
|
+
JSON objects are represented as RESP object, where the first element is the simple string {, followed by key-value pairs,
|
|
1031
|
+
each of which is a RESP bulk string.\n
|
|
1031
1032
|
|
|
1032
1033
|
|
|
1033
1034
|
Args:
|
|
@@ -1081,13 +1082,15 @@ async def strappend(
|
|
|
1081
1082
|
Args:
|
|
1082
1083
|
client (TGlideClient): The client to execute the command.
|
|
1083
1084
|
key (TEncodable): The key of the JSON document.
|
|
1084
|
-
value (TEncodable): The value to append to the string. Must be wrapped with single quotes. For example,
|
|
1085
|
+
value (TEncodable): The value to append to the string. Must be wrapped with single quotes. For example,
|
|
1086
|
+
to append "foo", pass '"foo"'.
|
|
1085
1087
|
path (Optional[TEncodable]): The path within the JSON document. Default to None.
|
|
1086
1088
|
|
|
1087
1089
|
Returns:
|
|
1088
1090
|
TJsonResponse[int]:
|
|
1089
1091
|
For JSONPath (`path` starts with `$`):
|
|
1090
|
-
Returns a list of integer replies for every possible path, indicating the length of the resulting string after
|
|
1092
|
+
Returns a list of integer replies for every possible path, indicating the length of the resulting string after
|
|
1093
|
+
appending `value`,
|
|
1091
1094
|
or None for JSON values matching the path that are not string.
|
|
1092
1095
|
If `key` doesn't exist, an error is raised.
|
|
1093
1096
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -1103,11 +1106,14 @@ async def strappend(
|
|
|
1103
1106
|
>>> await glide_json.set(client, "doc", "$", json.dumps({"a":"foo", "nested": {"a": "hello"}, "nested2": {"a": 31}}))
|
|
1104
1107
|
'OK'
|
|
1105
1108
|
>>> await glide_json.strappend(client, "doc", json.dumps("baz"), "$..a")
|
|
1106
|
-
[6, 8, None] # The new length of the string values at path '$..a' in the key stored at `doc` after the append
|
|
1109
|
+
[6, 8, None] # The new length of the string values at path '$..a' in the key stored at `doc` after the append
|
|
1110
|
+
# operation.
|
|
1107
1111
|
>>> await glide_json.strappend(client, "doc", '"foo"', "nested.a")
|
|
1108
|
-
11 # The length of the string value after appending "foo" to the string at path 'nested.array' in the key stored
|
|
1112
|
+
11 # The length of the string value after appending "foo" to the string at path 'nested.array' in the key stored
|
|
1113
|
+
# at `doc`.
|
|
1109
1114
|
>>> json.loads(await glide_json.get(client, json.dumps("doc"), "$"))
|
|
1110
|
-
[{"a":"foobaz", "nested": {"a": "hellobazfoo"}, "nested2": {"a": 31}}] # The updated JSON value in the key stored
|
|
1115
|
+
[{"a":"foobaz", "nested": {"a": "hellobazfoo"}, "nested2": {"a": 31}}] # The updated JSON value in the key stored
|
|
1116
|
+
# at `doc`.
|
|
1111
1117
|
"""
|
|
1112
1118
|
|
|
1113
1119
|
return cast(
|
|
@@ -1153,7 +1159,8 @@ async def strlen(
|
|
|
1153
1159
|
>>> await glide_json.strlen(client, "doc", "nested.a")
|
|
1154
1160
|
5 # The length of the JSON value at path 'nested.a' in the key stored at `doc`.
|
|
1155
1161
|
>>> await glide_json.strlen(client, "doc", "$")
|
|
1156
|
-
[None] # Returns an array with None since the value at root path does in the JSON document stored at `doc` is not
|
|
1162
|
+
[None] # Returns an array with None since the value at root path does in the JSON document stored at `doc` is not
|
|
1163
|
+
# a string.
|
|
1157
1164
|
>>> await glide_json.strlen(client, "non_existing_key", ".")
|
|
1158
1165
|
None # `key` doesn't exist.
|
|
1159
1166
|
"""
|
|
@@ -1194,14 +1201,21 @@ async def toggle(
|
|
|
1194
1201
|
Examples:
|
|
1195
1202
|
>>> from glide import glide_json
|
|
1196
1203
|
>>> import json
|
|
1197
|
-
>>> await glide_json.set(
|
|
1204
|
+
>>> await glide_json.set(
|
|
1205
|
+
... client,
|
|
1206
|
+
... "doc",
|
|
1207
|
+
... "$",
|
|
1208
|
+
... json.dumps({"bool": True, "nested": {"bool": False, "nested": {"bool": 10}}})
|
|
1209
|
+
... )
|
|
1198
1210
|
'OK'
|
|
1199
1211
|
>>> await glide_json.toggle(client, "doc", "$.bool")
|
|
1200
|
-
[False, True, None] # Indicates successful toggling of the Boolean values at path '$.bool' in the key stored at
|
|
1212
|
+
[False, True, None] # Indicates successful toggling of the Boolean values at path '$.bool' in the key stored at
|
|
1213
|
+
# `doc`.
|
|
1201
1214
|
>>> await glide_json.toggle(client, "doc", "bool")
|
|
1202
1215
|
True # Indicates successful toggling of the Boolean value at path 'bool' in the key stored at `doc`.
|
|
1203
1216
|
>>> json.loads(await glide_json.get(client, "doc", "$"))
|
|
1204
|
-
[{"bool": True, "nested": {"bool": True, "nested": {"bool": 10}}}] # The updated JSON value in the key stored at
|
|
1217
|
+
[{"bool": True, "nested": {"bool": True, "nested": {"bool": 10}}}] # The updated JSON value in the key stored at
|
|
1218
|
+
# `doc`.
|
|
1205
1219
|
"""
|
|
1206
1220
|
|
|
1207
1221
|
return cast(
|