valkey-glide 1.3.4rc1__cp313-cp313-macosx_11_0_arm64.whl → 2.0.0rc6__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.
Potentially problematic release.
This version of valkey-glide might be problematic. Click here for more details.
- glide/__init__.py +11 -7
- glide/async_commands/{transaction.py → batch.py} +1413 -987
- glide/async_commands/bitmap.py +94 -85
- glide/async_commands/cluster_commands.py +308 -123
- glide/async_commands/command_args.py +7 -6
- glide/async_commands/core.py +1304 -714
- glide/async_commands/server_modules/ft.py +83 -14
- glide/async_commands/server_modules/ft_options/ft_aggregate_options.py +15 -8
- glide/async_commands/server_modules/ft_options/ft_create_options.py +23 -11
- glide/async_commands/server_modules/ft_options/ft_profile_options.py +12 -7
- glide/async_commands/server_modules/ft_options/ft_search_options.py +12 -6
- glide/async_commands/server_modules/glide_json.py +134 -43
- glide/async_commands/server_modules/json_batch.py +157 -127
- glide/async_commands/sorted_set.py +39 -29
- glide/async_commands/standalone_commands.py +199 -95
- glide/async_commands/stream.py +94 -87
- glide/config.py +165 -105
- glide/constants.py +8 -4
- glide/glide.cpython-313-darwin.so +0 -0
- glide/glide_client.py +273 -94
- glide/logger.py +1 -1
- glide/protobuf/command_request_pb2.py +15 -15
- glide/protobuf/command_request_pb2.pyi +69 -46
- glide/protobuf/connection_request_pb2.py +15 -13
- glide/protobuf/connection_request_pb2.pyi +57 -29
- glide/protobuf/response_pb2.pyi +8 -9
- glide/protobuf_codec.py +7 -6
- glide/routes.py +41 -8
- {valkey_glide-1.3.4rc1.dist-info → valkey_glide-2.0.0rc6.dist-info}/METADATA +29 -8
- valkey_glide-2.0.0rc6.dist-info/RECORD +37 -0
- valkey_glide-1.3.4rc1.dist-info/RECORD +0 -37
- {valkey_glide-1.3.4rc1.dist-info → valkey_glide-2.0.0rc6.dist-info}/WHEEL +0 -0
|
@@ -9,7 +9,8 @@ Examples:
|
|
|
9
9
|
>>> json_str = json.dumps(value) # Convert Python dictionary to JSON string using json.dumps()
|
|
10
10
|
>>> await 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))
|
|
@@ -21,7 +22,6 @@ from typing import List, Optional, Union, cast
|
|
|
21
22
|
from glide.async_commands.core import ConditionalChange
|
|
22
23
|
from glide.constants import TOK, TEncodable, TJsonResponse, TJsonUniversalResponse
|
|
23
24
|
from glide.glide_client import TGlideClient
|
|
24
|
-
from glide.protobuf.command_request_pb2 import RequestType
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class JsonGetOptions:
|
|
@@ -126,7 +126,8 @@ async def set(
|
|
|
126
126
|
client (TGlideClient): The client to execute the command.
|
|
127
127
|
key (TEncodable): The key of the JSON document.
|
|
128
128
|
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
|
|
129
|
+
The key will be modified only if `value` is added as the last child in the specified `path`, or if the specified
|
|
130
|
+
`path` acts as the parent of a new child being added.
|
|
130
131
|
value (TEncodable): The value to set at the specific path, in JSON formatted bytes or str.
|
|
131
132
|
set_condition (Optional[ConditionalChange]): Set the value only if the given condition is met (within the key or path).
|
|
132
133
|
Equivalent to [`XX` | `NX`] in the RESP API. Defaults to None.
|
|
@@ -162,8 +163,10 @@ async def get(
|
|
|
162
163
|
Args:
|
|
163
164
|
client (TGlideClient): The client to execute the command.
|
|
164
165
|
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
|
-
|
|
166
|
+
paths (Optional[Union[TEncodable, List[TEncodable]]]): The path or list of paths within the JSON document.
|
|
167
|
+
Default to None.
|
|
168
|
+
options (Optional[JsonGetOptions]): Options for formatting the byte representation of the JSON data.
|
|
169
|
+
See `JsonGetOptions`.
|
|
167
170
|
|
|
168
171
|
Returns:
|
|
169
172
|
TJsonResponse[Optional[bytes]]:
|
|
@@ -177,8 +180,10 @@ async def get(
|
|
|
177
180
|
If `path` doesn't exist, an error is raised.
|
|
178
181
|
If `key` doesn't exist, returns None.
|
|
179
182
|
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
|
-
|
|
183
|
+
Returns a stringified JSON object in bytes, in which each path is a key, and it's corresponding value, is the
|
|
184
|
+
value as if the path was executed in the command as a single path.
|
|
185
|
+
In case of multiple paths, and `paths` are a mix of both JSONPath and legacy path, the command behaves as if all are
|
|
186
|
+
JSONPath paths.
|
|
182
187
|
For more information about the returned type, see `TJsonResponse`.
|
|
183
188
|
|
|
184
189
|
Examples:
|
|
@@ -190,9 +195,12 @@ async def get(
|
|
|
190
195
|
>>> await glide_json.get(client, "doc", "$")
|
|
191
196
|
b"[{\"a\":1.0,\"b\":2}]" # Returns the value at path '$' in the JSON document stored at `doc`.
|
|
192
197
|
>>> 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
|
|
198
|
+
b"{\n \"$.a\": [\n 1.0\n ],\n \"$.b\": [\n 2\n ]\n}" # Returns the values at paths '$.a' and '$.b' in the JSON
|
|
199
|
+
# document stored at `doc`, with specified
|
|
200
|
+
# formatting options.
|
|
194
201
|
>>> 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
|
|
202
|
+
b"[]" # Returns an empty array since the path '$.non_existing_path' does not exist in the JSON document
|
|
203
|
+
# stored at `doc`.
|
|
196
204
|
"""
|
|
197
205
|
args = ["JSON.GET", key]
|
|
198
206
|
if options:
|
|
@@ -224,7 +232,8 @@ async def arrappend(
|
|
|
224
232
|
Returns:
|
|
225
233
|
TJsonResponse[int]:
|
|
226
234
|
For JSONPath (`path` starts with `$`):
|
|
227
|
-
Returns a list of integer replies for every possible path, indicating the new length of the array after
|
|
235
|
+
Returns a list of integer replies for every possible path, indicating the new length of the array after
|
|
236
|
+
appending `values`,
|
|
228
237
|
or None for JSON values matching the path that are not an array.
|
|
229
238
|
If `path` doesn't exist, an empty array will be returned.
|
|
230
239
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -258,12 +267,14 @@ async def arrindex(
|
|
|
258
267
|
options: Optional[JsonArrIndexOptions] = None,
|
|
259
268
|
) -> TJsonResponse[int]:
|
|
260
269
|
"""
|
|
261
|
-
Searches for the first occurrence of a scalar JSON value (i.e., a value that is neither an object nor an array) within
|
|
270
|
+
Searches for the first occurrence of a scalar JSON value (i.e., a value that is neither an object nor an array) within
|
|
271
|
+
arrays at the specified `path` in the JSON document stored at `key`.
|
|
262
272
|
|
|
263
273
|
If specified, `options.start` and `options.end` define an inclusive-to-exclusive search range within the array.
|
|
264
274
|
(Where `options.start` is inclusive and `options.end` is exclusive).
|
|
265
275
|
|
|
266
|
-
Out-of-range indices adjust to the nearest valid position, and negative values count from the end (e.g., `-1` is the last
|
|
276
|
+
Out-of-range indices adjust to the nearest valid position, and negative values count from the end (e.g., `-1` is the last
|
|
277
|
+
element, `-2` the second last).
|
|
267
278
|
|
|
268
279
|
Setting `options.end` to `0` behaves like `-1`, extending the range to the array's end (inclusive).
|
|
269
280
|
|
|
@@ -274,18 +285,21 @@ async def arrindex(
|
|
|
274
285
|
key (TEncodable): The key of the JSON document.
|
|
275
286
|
path (TEncodable): The path within the JSON document.
|
|
276
287
|
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`
|
|
288
|
+
options (Optional[JsonArrIndexOptions]): Options specifying an inclusive `start` index and an optional exclusive `end`
|
|
289
|
+
index for a range-limited search.
|
|
278
290
|
Defaults to the full array if not provided. See `JsonArrIndexOptions`.
|
|
279
291
|
|
|
280
292
|
Returns:
|
|
281
293
|
Optional[TJsonResponse[int]]:
|
|
282
294
|
For JSONPath (`path` starts with `$`):
|
|
283
|
-
Returns an array of integers for every possible path, indicating of the first occurrence of `value`
|
|
295
|
+
Returns an array of integers for every possible path, indicating of the first occurrence of `value`
|
|
296
|
+
within the array,
|
|
284
297
|
or None for JSON values matching the path that are not an array.
|
|
285
298
|
A returned value of `-1` indicates that the value was not found in that particular array.
|
|
286
299
|
If `path` does not exist, an empty array will be returned.
|
|
287
300
|
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
|
|
301
|
+
Returns an integer representing the index of the first occurrence of `value` within the array at the
|
|
302
|
+
specified path.
|
|
289
303
|
A returned value of `-1` indicates that the value was not found in that particular array.
|
|
290
304
|
If multiple paths match, the index of the value from the first matching array is returned.
|
|
291
305
|
If the JSON value at the `path` is not an array or if `path` does not exist, an error is raised.
|
|
@@ -331,7 +345,8 @@ async def arrinsert(
|
|
|
331
345
|
values: List[TEncodable],
|
|
332
346
|
) -> TJsonResponse[int]:
|
|
333
347
|
"""
|
|
334
|
-
Inserts one or more values into the array at the specified `path` within the JSON document stored at `key`,
|
|
348
|
+
Inserts one or more values into the array at the specified `path` within the JSON document stored at `key`,
|
|
349
|
+
before the given `index`.
|
|
335
350
|
|
|
336
351
|
Args:
|
|
337
352
|
client (TGlideClient): The client to execute the command.
|
|
@@ -442,7 +457,8 @@ async def arrpop(
|
|
|
442
457
|
Args:
|
|
443
458
|
client (TGlideClient): The client to execute the command.
|
|
444
459
|
key (TEncodable): The key of the JSON document.
|
|
445
|
-
options (Optional[JsonArrPopOptions]): Options including the path and optional index. See `JsonArrPopOptions`.
|
|
460
|
+
options (Optional[JsonArrPopOptions]): Options including the path and optional index. See `JsonArrPopOptions`.
|
|
461
|
+
Default to None.
|
|
446
462
|
If not specified, attempts to pop the last element from the root value if it's an array.
|
|
447
463
|
If the root value is not an array, an error will be raised.
|
|
448
464
|
|
|
@@ -461,7 +477,12 @@ async def arrpop(
|
|
|
461
477
|
|
|
462
478
|
Examples:
|
|
463
479
|
>>> from glide import glide_json
|
|
464
|
-
>>> await glide_json.set(
|
|
480
|
+
>>> await glide_json.set(
|
|
481
|
+
... client,
|
|
482
|
+
... "doc",
|
|
483
|
+
... "$",
|
|
484
|
+
... '{"a": [1, 2, true], "b": {"a": [3, 4, ["value", 3, false], 5], "c": {"a": 42}}}'
|
|
485
|
+
... )
|
|
465
486
|
b'OK'
|
|
466
487
|
>>> await glide_json.arrpop(client, "doc", JsonArrPopOptions(path="$.a", index=1))
|
|
467
488
|
[b'2'] # Pop second element from array at path $.a
|
|
@@ -501,7 +522,8 @@ async def arrtrim(
|
|
|
501
522
|
end: int,
|
|
502
523
|
) -> TJsonResponse[int]:
|
|
503
524
|
"""
|
|
504
|
-
Trims an array at the specified `path` within the JSON document stored at `key` so that it becomes a subarray [start, end],
|
|
525
|
+
Trims an array at the specified `path` within the JSON document stored at `key` so that it becomes a subarray [start, end],
|
|
526
|
+
both inclusive.
|
|
505
527
|
If `start` < 0, it is treated as 0.
|
|
506
528
|
If `end` >= size (size of the array), it is treated as size-1.
|
|
507
529
|
If `start` >= size or `start` > `end`, the array is emptied and 0 is returned.
|
|
@@ -516,7 +538,8 @@ async def arrtrim(
|
|
|
516
538
|
Returns:
|
|
517
539
|
TJsonResponse[int]:
|
|
518
540
|
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
|
|
541
|
+
Returns a list of integer replies for every possible path, indicating the new length of the array, or None for
|
|
542
|
+
JSON values matching the path that are not an array.
|
|
520
543
|
If a value is an empty array, its corresponding return value is 0.
|
|
521
544
|
If `path` doesn't exist, an empty array will be returned.
|
|
522
545
|
For legacy path (`path` doesn't starts with `$`):
|
|
@@ -566,12 +589,18 @@ async def clear(
|
|
|
566
589
|
Returns:
|
|
567
590
|
int: The number of containers cleared, numeric values zeroed, and booleans toggled to `false`,
|
|
568
591
|
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),
|
|
592
|
+
If `path` doesn't exist, or the value at `path` is already empty (e.g., an empty array, object, or string),
|
|
593
|
+
0 is returned.
|
|
570
594
|
If `key doesn't exist, an error is raised.
|
|
571
595
|
|
|
572
596
|
Examples:
|
|
573
597
|
>>> from glide import glide_json
|
|
574
|
-
>>> await glide_json.set(
|
|
598
|
+
>>> await glide_json.set(
|
|
599
|
+
... client,
|
|
600
|
+
... "doc",
|
|
601
|
+
... "$",
|
|
602
|
+
... '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14, "nullVal": null}'
|
|
603
|
+
... )
|
|
575
604
|
'OK' # JSON document is successfully set.
|
|
576
605
|
>>> await glide_json.clear(client, "doc", "$.*")
|
|
577
606
|
6 # 6 values are cleared (arrays/objects/strings/numbers/booleans), but `null` remains as is.
|
|
@@ -580,7 +609,18 @@ async def clear(
|
|
|
580
609
|
>>> await glide_json.clear(client, "doc", "$.*")
|
|
581
610
|
0 # No further clearing needed since the containers are already empty and the values are defaults.
|
|
582
611
|
|
|
583
|
-
>>> await glide_json.set(
|
|
612
|
+
>>> await glide_json.set(
|
|
613
|
+
... client,
|
|
614
|
+
... "doc",
|
|
615
|
+
... "$",
|
|
616
|
+
... (
|
|
617
|
+
... '{"a": 1, '
|
|
618
|
+
... '"b": {"a": [5, 6, 7], "b": {"a": true}}, '
|
|
619
|
+
... '"c": {"a": "value", "b": {"a": 3.5}}, '
|
|
620
|
+
... '"d": {"a": {"foo": "foo"}}, '
|
|
621
|
+
... '"nullVal": null}'
|
|
622
|
+
... )
|
|
623
|
+
... )
|
|
584
624
|
'OK'
|
|
585
625
|
>>> await glide_json.clear(client, "doc", "b.a[1:3]")
|
|
586
626
|
2 # 2 elements (`6` and `7`) are cleared.
|
|
@@ -609,7 +649,8 @@ async def debug_fields(
|
|
|
609
649
|
"""
|
|
610
650
|
Returns the number of fields of the JSON value at the specified `path` within the JSON document stored at `key`.
|
|
611
651
|
- **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.
|
|
652
|
+
- **Arrays and Objects:**: Each item in an array and each key-value pair in an object is counted as one field.
|
|
653
|
+
(Each top-level value counts as one field, regardless of it's type.)
|
|
613
654
|
- Their nested values are counted recursively and added to the total.
|
|
614
655
|
- **Example**: For the JSON `{"a": 1, "b": [2, 3, {"c": 4}]}`, the count would be:
|
|
615
656
|
- Top-level: 2 fields (`"a"` and `"b"`)
|
|
@@ -643,7 +684,22 @@ async def debug_fields(
|
|
|
643
684
|
>>> await glide_json.debug_fields(client, "k1", ".")
|
|
644
685
|
14 # 9 top-level fields + 5 nested address fields
|
|
645
686
|
|
|
646
|
-
>>> await glide_json.set(
|
|
687
|
+
>>> await glide_json.set(
|
|
688
|
+
... client,
|
|
689
|
+
... "k1",
|
|
690
|
+
... "$",
|
|
691
|
+
... (
|
|
692
|
+
... '{"firstName":"John", '
|
|
693
|
+
... '"lastName":"Smith", '
|
|
694
|
+
... '"age":27, '
|
|
695
|
+
... '"weight":135.25, '
|
|
696
|
+
... '"isAlive":true, '
|
|
697
|
+
... '"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"}, '
|
|
698
|
+
... '"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}], '
|
|
699
|
+
... '"children":[], '
|
|
700
|
+
... '"spouse":null}'
|
|
701
|
+
... )
|
|
702
|
+
... )
|
|
647
703
|
'OK'
|
|
648
704
|
>>> await glide_json.debug_fields(client, "k1")
|
|
649
705
|
19
|
|
@@ -692,7 +748,22 @@ async def debug_memory(
|
|
|
692
748
|
>>> await glide_json.debug_memory(client, "k1", "$[*]")
|
|
693
749
|
[16, 16, 19, 16, 16, 16, 16, 66, 64]
|
|
694
750
|
|
|
695
|
-
>>> await glide_json.set(
|
|
751
|
+
>>> await glide_json.set(
|
|
752
|
+
... client,
|
|
753
|
+
... "k1",
|
|
754
|
+
... "$",
|
|
755
|
+
... (
|
|
756
|
+
... '{"firstName":"John", '
|
|
757
|
+
... '"lastName":"Smith", '
|
|
758
|
+
... '"age":27, '
|
|
759
|
+
... '"weight":135.25, '
|
|
760
|
+
... '"isAlive":true, '
|
|
761
|
+
... '"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"}, '
|
|
762
|
+
... '"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}], '
|
|
763
|
+
... '"children":[], '
|
|
764
|
+
... '"spouse":null}'
|
|
765
|
+
... )
|
|
766
|
+
... )
|
|
696
767
|
'OK'
|
|
697
768
|
>>> await glide_json.debug_memory(client, "k1")
|
|
698
769
|
472
|
|
@@ -816,14 +887,16 @@ async def mget(
|
|
|
816
887
|
>>> import json
|
|
817
888
|
>>> json_strs = await glide_json.mget(client, ["doc1", "doc2"], "$")
|
|
818
889
|
>>> [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
|
|
890
|
+
[[{"a": 1.0, "b": 2}], [{"a": 2.0, "b": {"a": 3.0, "b" : 4.0}}]] # JSON objects retrieved from keys
|
|
891
|
+
# `doc1` and `doc2`
|
|
820
892
|
>>> await glide_json.mget(client, ["doc1", "doc2"], "$.a")
|
|
821
893
|
[b"[1.0]", b"[2.0]"] # Returns values at path '$.a' for the JSON documents stored at `doc1` and `doc2`.
|
|
822
894
|
>>> 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
|
|
895
|
+
[None] # Returns an empty array since the path '$.non_existing_path' does not exist in the JSON document
|
|
896
|
+
# stored at `doc1`.
|
|
824
897
|
"""
|
|
825
898
|
args = ["JSON.MGET"] + keys + [path]
|
|
826
|
-
return cast(
|
|
899
|
+
return cast(List[Optional[bytes]], await client.custom_command(args))
|
|
827
900
|
|
|
828
901
|
|
|
829
902
|
async def numincrby(
|
|
@@ -844,7 +917,8 @@ async def numincrby(
|
|
|
844
917
|
Returns:
|
|
845
918
|
bytes:
|
|
846
919
|
For JSONPath (`path` starts with `$`):
|
|
847
|
-
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
920
|
+
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
921
|
+
incrementing for each matched `path`.
|
|
848
922
|
If a value is not a number, its corresponding return value will be `null`.
|
|
849
923
|
If `path` doesn't exist, a byte string representation of an empty array will be returned.
|
|
850
924
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -886,7 +960,8 @@ async def nummultby(
|
|
|
886
960
|
Returns:
|
|
887
961
|
bytes:
|
|
888
962
|
For JSONPath (`path` starts with `$`):
|
|
889
|
-
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
963
|
+
Returns a bytes string representation of an array of bulk strings, indicating the new values after
|
|
964
|
+
multiplication for each matched `path`.
|
|
890
965
|
If a value is not a number, its corresponding return value will be `null`.
|
|
891
966
|
If `path` doesn't exist, a byte string representation of an empty array will be returned.
|
|
892
967
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -916,7 +991,8 @@ async def objlen(
|
|
|
916
991
|
path: Optional[TEncodable] = None,
|
|
917
992
|
) -> Optional[TJsonResponse[int]]:
|
|
918
993
|
"""
|
|
919
|
-
Retrieves the number of key-value pairs in the object stored at the specified `path` within the JSON document stored at
|
|
994
|
+
Retrieves the number of key-value pairs in the object stored at the specified `path` within the JSON document stored at
|
|
995
|
+
`key`.
|
|
920
996
|
|
|
921
997
|
Args:
|
|
922
998
|
client (TGlideClient): The client to execute the command.
|
|
@@ -1026,8 +1102,10 @@ async def resp(
|
|
|
1026
1102
|
JSON integers are mapped to RESP Integers.\n
|
|
1027
1103
|
JSON doubles are mapped to RESP Bulk Strings.\n
|
|
1028
1104
|
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
|
-
|
|
1105
|
+
JSON arrays are represented as RESP arrays, where the first element is the simple string [, followed by the array's
|
|
1106
|
+
elements.\n
|
|
1107
|
+
JSON objects are represented as RESP object, where the first element is the simple string {, followed by key-value pairs,
|
|
1108
|
+
each of which is a RESP bulk string.\n
|
|
1031
1109
|
|
|
1032
1110
|
|
|
1033
1111
|
Args:
|
|
@@ -1081,13 +1159,15 @@ async def strappend(
|
|
|
1081
1159
|
Args:
|
|
1082
1160
|
client (TGlideClient): The client to execute the command.
|
|
1083
1161
|
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,
|
|
1162
|
+
value (TEncodable): The value to append to the string. Must be wrapped with single quotes. For example,
|
|
1163
|
+
to append "foo", pass '"foo"'.
|
|
1085
1164
|
path (Optional[TEncodable]): The path within the JSON document. Default to None.
|
|
1086
1165
|
|
|
1087
1166
|
Returns:
|
|
1088
1167
|
TJsonResponse[int]:
|
|
1089
1168
|
For JSONPath (`path` starts with `$`):
|
|
1090
|
-
Returns a list of integer replies for every possible path, indicating the length of the resulting string after
|
|
1169
|
+
Returns a list of integer replies for every possible path, indicating the length of the resulting string after
|
|
1170
|
+
appending `value`,
|
|
1091
1171
|
or None for JSON values matching the path that are not string.
|
|
1092
1172
|
If `key` doesn't exist, an error is raised.
|
|
1093
1173
|
For legacy path (`path` doesn't start with `$`):
|
|
@@ -1103,11 +1183,14 @@ async def strappend(
|
|
|
1103
1183
|
>>> await glide_json.set(client, "doc", "$", json.dumps({"a":"foo", "nested": {"a": "hello"}, "nested2": {"a": 31}}))
|
|
1104
1184
|
'OK'
|
|
1105
1185
|
>>> 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
|
|
1186
|
+
[6, 8, None] # The new length of the string values at path '$..a' in the key stored at `doc` after the append
|
|
1187
|
+
# operation.
|
|
1107
1188
|
>>> 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
|
|
1189
|
+
11 # The length of the string value after appending "foo" to the string at path 'nested.array' in the key stored
|
|
1190
|
+
# at `doc`.
|
|
1109
1191
|
>>> 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
|
|
1192
|
+
[{"a":"foobaz", "nested": {"a": "hellobazfoo"}, "nested2": {"a": 31}}] # The updated JSON value in the key stored
|
|
1193
|
+
# at `doc`.
|
|
1111
1194
|
"""
|
|
1112
1195
|
|
|
1113
1196
|
return cast(
|
|
@@ -1153,7 +1236,8 @@ async def strlen(
|
|
|
1153
1236
|
>>> await glide_json.strlen(client, "doc", "nested.a")
|
|
1154
1237
|
5 # The length of the JSON value at path 'nested.a' in the key stored at `doc`.
|
|
1155
1238
|
>>> 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
|
|
1239
|
+
[None] # Returns an array with None since the value at root path does in the JSON document stored at `doc` is not
|
|
1240
|
+
# a string.
|
|
1157
1241
|
>>> await glide_json.strlen(client, "non_existing_key", ".")
|
|
1158
1242
|
None # `key` doesn't exist.
|
|
1159
1243
|
"""
|
|
@@ -1194,14 +1278,21 @@ async def toggle(
|
|
|
1194
1278
|
Examples:
|
|
1195
1279
|
>>> from glide import glide_json
|
|
1196
1280
|
>>> import json
|
|
1197
|
-
>>> await glide_json.set(
|
|
1281
|
+
>>> await glide_json.set(
|
|
1282
|
+
... client,
|
|
1283
|
+
... "doc",
|
|
1284
|
+
... "$",
|
|
1285
|
+
... json.dumps({"bool": True, "nested": {"bool": False, "nested": {"bool": 10}}})
|
|
1286
|
+
... )
|
|
1198
1287
|
'OK'
|
|
1199
1288
|
>>> 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
|
|
1289
|
+
[False, True, None] # Indicates successful toggling of the Boolean values at path '$.bool' in the key stored at
|
|
1290
|
+
# `doc`.
|
|
1201
1291
|
>>> await glide_json.toggle(client, "doc", "bool")
|
|
1202
1292
|
True # Indicates successful toggling of the Boolean value at path 'bool' in the key stored at `doc`.
|
|
1203
1293
|
>>> 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
|
|
1294
|
+
[{"bool": True, "nested": {"bool": True, "nested": {"bool": 10}}}] # The updated JSON value in the key stored at
|
|
1295
|
+
# `doc`.
|
|
1205
1296
|
"""
|
|
1206
1297
|
|
|
1207
1298
|
return cast(
|