valkey-glide 1.2.0rc14__cp311-cp311-macosx_11_0_arm64.whl → 2.2.3__cp311-cp311-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 +169 -104
- glide/async_commands/cluster_commands.py +367 -172
- glide/async_commands/core.py +1808 -1026
- glide/async_commands/{server_modules/ft.py → ft.py} +91 -21
- glide/async_commands/{server_modules/glide_json.py → glide_json.py} +161 -146
- glide/async_commands/standalone_commands.py +204 -136
- glide/glide.cpython-311-darwin.so +0 -0
- glide/glide.pyi +26 -1
- glide/glide_client.py +355 -136
- 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 +1845 -1059
- glide_shared/commands/batch_options.py +261 -0
- {glide/async_commands → glide_shared/commands}/bitmap.py +96 -86
- {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 +17 -9
- glide_shared/commands/server_modules/json_batch.py +820 -0
- glide_shared/commands/server_modules/json_options.py +93 -0
- {glide/async_commands → glide_shared/commands}/sorted_set.py +42 -32
- {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.3.dist-info/METADATA +211 -0
- valkey_glide-2.2.3.dist-info/RECORD +40 -0
- {valkey_glide-1.2.0rc14.dist-info → valkey_glide-2.2.3.dist-info}/WHEEL +1 -1
- glide/config.py +0 -521
- glide/protobuf/command_request_pb2.py +0 -54
- glide/protobuf/command_request_pb2.pyi +0 -1161
- glide/protobuf/connection_request_pb2.py +0 -52
- glide/protobuf/connection_request_pb2.pyi +0 -287
- glide/protobuf/response_pb2.pyi +0 -101
- glide/routes.py +0 -114
- valkey_glide-1.2.0rc14.dist-info/METADATA +0 -122
- valkey_glide-1.2.0rc14.dist-info/RECORD +0 -36
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
|
@@ -2,30 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Dict, List, Mapping, Optional, Union, cast
|
|
6
6
|
|
|
7
|
-
from glide.
|
|
8
|
-
from
|
|
9
|
-
|
|
7
|
+
from glide.glide import ClusterScanCursor, Script
|
|
8
|
+
from glide_shared.commands.batch import ClusterBatch
|
|
9
|
+
from glide_shared.commands.batch_options import ClusterBatchOptions
|
|
10
|
+
from glide_shared.commands.command_args import ObjectType
|
|
11
|
+
from glide_shared.commands.core_options import (
|
|
10
12
|
FlushMode,
|
|
11
13
|
FunctionRestorePolicy,
|
|
12
14
|
InfoSection,
|
|
13
|
-
_build_sort_args,
|
|
14
15
|
)
|
|
15
|
-
from
|
|
16
|
-
from glide.constants import (
|
|
16
|
+
from glide_shared.constants import (
|
|
17
17
|
TOK,
|
|
18
18
|
TClusterResponse,
|
|
19
19
|
TEncodable,
|
|
20
20
|
TFunctionListResponse,
|
|
21
21
|
TFunctionStatsSingleNodeResponse,
|
|
22
22
|
TResult,
|
|
23
|
-
TSingleNodeRoute,
|
|
24
23
|
)
|
|
25
|
-
from
|
|
26
|
-
from
|
|
24
|
+
from glide_shared.exceptions import RequestError
|
|
25
|
+
from glide_shared.protobuf.command_request_pb2 import RequestType
|
|
26
|
+
from glide_shared.routes import Route
|
|
27
27
|
|
|
28
|
-
from
|
|
28
|
+
from .core import CoreCommands
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class ClusterCommands(CoreCommands):
|
|
@@ -37,13 +37,19 @@ class ClusterCommands(CoreCommands):
|
|
|
37
37
|
See the [Valkey GLIDE Wiki](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command)
|
|
38
38
|
for details on the restrictions and limitations of the custom command API.
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
This function should only be used for single-response commands. Commands that don't return complete response and awaits
|
|
41
|
+
(such as SUBSCRIBE), or that return potentially more than a single response (such as XREAD), or that change the
|
|
42
|
+
client's behavior (such as entering pub/sub mode on RESP2 connections) shouldn't be called using this function.
|
|
43
|
+
|
|
44
|
+
For example - Return a list of all pub/sub clients from all nodes::
|
|
45
|
+
|
|
46
|
+
await client.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"], AllNodes())
|
|
41
47
|
|
|
42
|
-
connection.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"], AllNodes())
|
|
43
48
|
Args:
|
|
44
49
|
command_args (List[TEncodable]): List of the command's arguments, where each argument is either a string or bytes.
|
|
45
50
|
Every part of the command, including the command name and subcommands, should be added as a separate value in args.
|
|
46
|
-
route (Optional[Route]): The command will be routed automatically based on the passed command's default request
|
|
51
|
+
route (Optional[Route]): The command will be routed automatically based on the passed command's default request
|
|
52
|
+
policy, unless `route` is provided, in which
|
|
47
53
|
case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
48
54
|
|
|
49
55
|
Returns:
|
|
@@ -61,13 +67,16 @@ class ClusterCommands(CoreCommands):
|
|
|
61
67
|
) -> TClusterResponse[bytes]:
|
|
62
68
|
"""
|
|
63
69
|
Get information and statistics about the server.
|
|
64
|
-
|
|
70
|
+
|
|
71
|
+
Starting from server version 7, command supports multiple section arguments.
|
|
72
|
+
|
|
73
|
+
See [valkey.io](https://valkey.io/commands/info/) for details.
|
|
65
74
|
|
|
66
75
|
Args:
|
|
67
76
|
sections (Optional[List[InfoSection]]): A list of InfoSection values specifying which sections of
|
|
68
|
-
|
|
69
|
-
route (Optional[Route]): The command will be routed to all primaries, unless `route` is provided, in
|
|
70
|
-
|
|
77
|
+
information to retrieve. When no parameter is provided, the default option is assumed.
|
|
78
|
+
route (Optional[Route]): The command will be routed to all primaries, unless `route` is provided, in
|
|
79
|
+
which case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
71
80
|
|
|
72
81
|
Returns:
|
|
73
82
|
TClusterResponse[bytes]: If a single node route is requested, returns a bytes string containing the information for
|
|
@@ -84,27 +93,120 @@ class ClusterCommands(CoreCommands):
|
|
|
84
93
|
|
|
85
94
|
async def exec(
|
|
86
95
|
self,
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
batch: ClusterBatch,
|
|
97
|
+
raise_on_error: bool,
|
|
98
|
+
options: Optional[ClusterBatchOptions] = None,
|
|
89
99
|
) -> Optional[List[TResult]]:
|
|
90
100
|
"""
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
Executes a batch by processing the queued commands.
|
|
102
|
+
|
|
103
|
+
**Routing Behavior:**
|
|
104
|
+
|
|
105
|
+
- If a `route` is specified in `ClusterBatchOptions`, the entire batch is sent
|
|
106
|
+
to the specified node.
|
|
107
|
+
- If no `route` is specified:
|
|
108
|
+
- **Atomic batches (Transactions):** Routed to the slot owner of the
|
|
109
|
+
first key in the batch. If no key is found, the request is sent to a random node.
|
|
110
|
+
- **Non-atomic batches (Pipelines):** Each command is routed to the node
|
|
111
|
+
owning the corresponding key's slot. If no key is present, routing follows the
|
|
112
|
+
command's request policy. Multi-node commands are automatically split and
|
|
113
|
+
dispatched to the appropriate nodes.
|
|
114
|
+
|
|
115
|
+
**Behavior notes:**
|
|
116
|
+
|
|
117
|
+
- **Atomic Batches (Transactions):** All key-based commands must map to the
|
|
118
|
+
same hash slot. If keys span different slots, the transaction will fail. If the
|
|
119
|
+
transaction fails due to a `WATCH` command, `EXEC` will return `None`.
|
|
120
|
+
|
|
121
|
+
**Retry and Redirection:**
|
|
122
|
+
|
|
123
|
+
- If a redirection error occurs:
|
|
124
|
+
- **Atomic batches (Transactions):** The entire transaction will be
|
|
125
|
+
redirected.
|
|
126
|
+
- **Non-atomic batches:** Only commands that encountered redirection
|
|
127
|
+
errors will be redirected.
|
|
128
|
+
- Retries for failures will be handled according to the configured `BatchRetryStrategy`.
|
|
93
129
|
|
|
94
130
|
Args:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
131
|
+
batch (ClusterBatch): A `ClusterBatch` containing the commands to execute.
|
|
132
|
+
raise_on_error (bool): Determines how errors are handled within the batch response.
|
|
133
|
+
When set to `True`, the first encountered error in the batch will be raised as an
|
|
134
|
+
exception of type `RequestError` after all retries and reconnections have been
|
|
135
|
+
executed.
|
|
136
|
+
When set to `False`, errors will be included as part of the batch response,
|
|
137
|
+
allowing the caller to process both successful and failed commands together. In this case,
|
|
138
|
+
error details will be provided as instances of `RequestError`.
|
|
139
|
+
options (Optional[ClusterBatchOptions]): A `ClusterBatchOptions` object containing execution options.
|
|
99
140
|
|
|
100
141
|
Returns:
|
|
101
|
-
Optional[List[TResult]]:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
142
|
+
Optional[List[TResult]]: An array of results, where each entry
|
|
143
|
+
corresponds to a command's execution result.
|
|
144
|
+
|
|
145
|
+
See Also:
|
|
146
|
+
[Valkey Transactions (Atomic Batches)](https://valkey.io/docs/topics/transactions/)
|
|
147
|
+
[Valkey Pipelines (Non-Atomic Batches)](https://valkey.io/docs/topics/pipelining/)
|
|
148
|
+
|
|
149
|
+
Examples:
|
|
150
|
+
# Atomic batch (transaction): all keys must share the same hash slot
|
|
151
|
+
>>> options = ClusterBatchOptions(timeout=1000) # Set a timeout of 1000 milliseconds
|
|
152
|
+
>>> atomic_batch = ClusterBatch(is_atomic=True)
|
|
153
|
+
>>> atomic_batch.set("key", "1")
|
|
154
|
+
>>> atomic_batch.incr("key")
|
|
155
|
+
>>> atomic_batch.get("key")
|
|
156
|
+
>>> atomic_result = await cluster_client.exec(atomic_batch, False, options)
|
|
157
|
+
>>> print(f"Atomic Batch Result: {atomic_result}")
|
|
158
|
+
# Output: Atomic Batch Result: [OK, 2, 2]
|
|
159
|
+
|
|
160
|
+
# Non-atomic batch (pipeline): keys may span different hash slots
|
|
161
|
+
>>> retry_strategy = BatchRetryStrategy(retry_server_error=True, retry_connection_error=False)
|
|
162
|
+
>>> pipeline_options = ClusterBatchOptions(retry_strategy=retry_strategy)
|
|
163
|
+
>>> non_atomic_batch = ClusterBatch(is_atomic=False)
|
|
164
|
+
>>> non_atomic_batch.set("key1", "value1")
|
|
165
|
+
>>> non_atomic_batch.set("key2", "value2")
|
|
166
|
+
>>> non_atomic_batch.get("key1")
|
|
167
|
+
>>> non_atomic_batch.get("key2")
|
|
168
|
+
>>> non_atomic_result = await cluster_client.exec(non_atomic_batch, False, pipeline_options)
|
|
169
|
+
>>> print(f"Non-Atomic Batch Result: {non_atomic_result}")
|
|
170
|
+
# Output: Non-Atomic Batch Result: [OK, OK, value1, value2]
|
|
171
|
+
"""
|
|
172
|
+
commands = batch.commands[:]
|
|
173
|
+
|
|
174
|
+
if (
|
|
175
|
+
batch.is_atomic
|
|
176
|
+
and options
|
|
177
|
+
and options.retry_strategy
|
|
178
|
+
and (
|
|
179
|
+
options.retry_strategy.retry_server_error
|
|
180
|
+
or options.retry_strategy.retry_connection_error
|
|
181
|
+
)
|
|
182
|
+
):
|
|
183
|
+
raise RequestError(
|
|
184
|
+
"Retry strategies are not supported for atomic batches (transactions). "
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Extract values to make the _execute_batch call cleaner
|
|
188
|
+
retry_server_error = (
|
|
189
|
+
options.retry_strategy.retry_server_error
|
|
190
|
+
if options and options.retry_strategy
|
|
191
|
+
else False
|
|
192
|
+
)
|
|
193
|
+
retry_connection_error = (
|
|
194
|
+
options.retry_strategy.retry_connection_error
|
|
195
|
+
if options and options.retry_strategy
|
|
196
|
+
else False
|
|
197
|
+
)
|
|
198
|
+
route = options.route if options else None
|
|
199
|
+
timeout = options.timeout if options else None
|
|
200
|
+
|
|
201
|
+
return await self._execute_batch(
|
|
202
|
+
commands,
|
|
203
|
+
batch.is_atomic,
|
|
204
|
+
raise_on_error,
|
|
205
|
+
retry_server_error,
|
|
206
|
+
retry_connection_error,
|
|
207
|
+
route,
|
|
208
|
+
timeout,
|
|
209
|
+
)
|
|
108
210
|
|
|
109
211
|
async def config_resetstat(
|
|
110
212
|
self,
|
|
@@ -112,11 +214,12 @@ class ClusterCommands(CoreCommands):
|
|
|
112
214
|
) -> TOK:
|
|
113
215
|
"""
|
|
114
216
|
Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM commands.
|
|
115
|
-
|
|
217
|
+
|
|
218
|
+
See [valkey.io](https://valkey.io/commands/config-resetstat/) for details.
|
|
116
219
|
|
|
117
220
|
Args:
|
|
118
|
-
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
119
|
-
|
|
221
|
+
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
222
|
+
which case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
120
223
|
|
|
121
224
|
Returns:
|
|
122
225
|
OK: Returns "OK" to confirm that the statistics were successfully reset.
|
|
@@ -131,11 +234,12 @@ class ClusterCommands(CoreCommands):
|
|
|
131
234
|
) -> TOK:
|
|
132
235
|
"""
|
|
133
236
|
Rewrite the configuration file with the current configuration.
|
|
134
|
-
|
|
237
|
+
|
|
238
|
+
See [valkey.io](https://valkey.io/commands/config-rewrite/) for details.
|
|
135
239
|
|
|
136
240
|
Args:
|
|
137
|
-
route (Optional[TRoute]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
138
|
-
|
|
241
|
+
route (Optional[TRoute]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
242
|
+
which case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
139
243
|
|
|
140
244
|
Returns:
|
|
141
245
|
OK: OK is returned when the configuration was rewritten properly. Otherwise an error is raised.
|
|
@@ -154,15 +258,18 @@ class ClusterCommands(CoreCommands):
|
|
|
154
258
|
) -> TClusterResponse[int]:
|
|
155
259
|
"""
|
|
156
260
|
Returns the current connection id.
|
|
157
|
-
|
|
261
|
+
|
|
262
|
+
See [valkey.io](https://valkey.io/commands/client-id/) for more information.
|
|
158
263
|
|
|
159
264
|
Args:
|
|
160
265
|
route (Optional[Route]): The command will be sent to a random node, unless `route` is provided, in which
|
|
161
|
-
|
|
266
|
+
case the client will route the command to the nodes defined by `route`.
|
|
162
267
|
|
|
163
268
|
Returns:
|
|
164
269
|
TClusterResponse[int]: The id of the client.
|
|
270
|
+
|
|
165
271
|
If a single node route is requested, returns a int representing the client's id.
|
|
272
|
+
|
|
166
273
|
Otherwise, returns a dict of [byte , int] where each key contains the address of
|
|
167
274
|
the queried node and the value contains the client's id.
|
|
168
275
|
"""
|
|
@@ -176,14 +283,14 @@ class ClusterCommands(CoreCommands):
|
|
|
176
283
|
) -> bytes:
|
|
177
284
|
"""
|
|
178
285
|
Ping the server.
|
|
179
|
-
|
|
286
|
+
|
|
287
|
+
See [valkey.io](https://valkey.io/commands/ping/) for more details.
|
|
180
288
|
|
|
181
289
|
Args:
|
|
182
290
|
message (Optional[TEncodable]): An optional message to include in the PING command. If not provided,
|
|
183
|
-
|
|
184
|
-
|
|
291
|
+
the server will respond with b"PONG". If provided, the server will respond with a copy of the message.
|
|
185
292
|
route (Optional[Route]): The command will be sent to all primaries, unless `route` is provided, in which
|
|
186
|
-
|
|
293
|
+
case the client will route the command to the nodes defined by `route`
|
|
187
294
|
|
|
188
295
|
Returns:
|
|
189
296
|
bytes: b'PONG' if `message` is not provided, otherwise return a copy of `message`.
|
|
@@ -204,18 +311,22 @@ class ClusterCommands(CoreCommands):
|
|
|
204
311
|
) -> TClusterResponse[Dict[bytes, bytes]]:
|
|
205
312
|
"""
|
|
206
313
|
Get the values of configuration parameters.
|
|
207
|
-
|
|
314
|
+
Starting from server version 7, command supports multiple parameters.
|
|
315
|
+
|
|
316
|
+
See [valkey.io](https://valkey.io/commands/config-get/) for details.
|
|
208
317
|
|
|
209
318
|
Args:
|
|
210
319
|
parameters (List[TEncodable]): A list of configuration parameter names to retrieve values for.
|
|
211
|
-
|
|
212
320
|
route (Optional[Route]): The command will be routed to a random node, unless `route` is provided,
|
|
213
|
-
|
|
321
|
+
in which case the client will route the command to the nodes defined by `route`.
|
|
214
322
|
|
|
215
323
|
Returns:
|
|
216
324
|
TClusterResponse[Dict[bytes, bytes]]: A dictionary of values corresponding to the
|
|
217
325
|
configuration parameters.
|
|
218
|
-
When specifying a route other than a single node, response will be
|
|
326
|
+
When specifying a route other than a single node, response will be::
|
|
327
|
+
|
|
328
|
+
{Address (bytes) : response (Dict[bytes, bytes]) , ... }
|
|
329
|
+
|
|
219
330
|
with type of Dict[bytes, Dict[bytes, bytes]].
|
|
220
331
|
|
|
221
332
|
Examples:
|
|
@@ -236,14 +347,15 @@ class ClusterCommands(CoreCommands):
|
|
|
236
347
|
) -> TOK:
|
|
237
348
|
"""
|
|
238
349
|
Set configuration parameters to the specified values.
|
|
239
|
-
|
|
350
|
+
Starting from server version 7, command supports multiple parameters.
|
|
351
|
+
|
|
352
|
+
See [valkey.io](https://valkey.io/commands/config-set/) for details.
|
|
240
353
|
|
|
241
354
|
Args:
|
|
242
355
|
parameters_map (Mapping[TEncodable, TEncodable]): A map consisting of configuration
|
|
243
|
-
|
|
244
|
-
|
|
356
|
+
parameters and their respective values to set.
|
|
245
357
|
route (Optional[Route]): The command will be routed to all nodes, unless `route` is provided,
|
|
246
|
-
|
|
358
|
+
in which case the client will route the command to the nodes defined by `route`.
|
|
247
359
|
|
|
248
360
|
Returns:
|
|
249
361
|
OK: Returns OK if all configurations have been successfully set. Otherwise, raises an error.
|
|
@@ -265,17 +377,22 @@ class ClusterCommands(CoreCommands):
|
|
|
265
377
|
) -> TClusterResponse[Optional[bytes]]:
|
|
266
378
|
"""
|
|
267
379
|
Get the name of the connection to which the request is routed.
|
|
268
|
-
|
|
380
|
+
|
|
381
|
+
See [valkey.io](https://valkey.io/commands/client-getname/) for more details.
|
|
269
382
|
|
|
270
383
|
Args:
|
|
271
384
|
route (Optional[Route]): The command will be routed to a random node, unless `route` is provided,
|
|
272
|
-
|
|
385
|
+
in which case the client will route the command to the nodes defined by `route`.
|
|
273
386
|
|
|
274
387
|
Returns:
|
|
275
388
|
TClusterResponse[Optional[bytes]]: The name of the client connection as a bytes string if a name is set,
|
|
276
389
|
or None if no name is assigned.
|
|
277
|
-
|
|
278
|
-
|
|
390
|
+
|
|
391
|
+
When specifying a route other than a single node, response will be::
|
|
392
|
+
|
|
393
|
+
{Address (bytes) : response (Optional[bytes]) , ... }
|
|
394
|
+
|
|
395
|
+
with type of Dict[str, Optional[str]].
|
|
279
396
|
|
|
280
397
|
Examples:
|
|
281
398
|
>>> await client.client_getname()
|
|
@@ -291,15 +408,18 @@ class ClusterCommands(CoreCommands):
|
|
|
291
408
|
async def dbsize(self, route: Optional[Route] = None) -> int:
|
|
292
409
|
"""
|
|
293
410
|
Returns the number of keys in the database.
|
|
294
|
-
|
|
411
|
+
|
|
412
|
+
See [valkey.io](https://valkey.io/commands/dbsize) for more details.
|
|
295
413
|
|
|
296
414
|
Args:
|
|
297
415
|
route (Optional[Route]): The command will be routed to all primaries, unless `route` is provided,
|
|
298
|
-
|
|
416
|
+
in which case the client will route the command to the nodes defined by `route`.
|
|
299
417
|
|
|
300
418
|
Returns:
|
|
301
419
|
int: The number of keys in the database.
|
|
302
|
-
|
|
420
|
+
|
|
421
|
+
In the case of routing the query to multiple nodes, returns the aggregated number of keys across the
|
|
422
|
+
different nodes.
|
|
303
423
|
|
|
304
424
|
Examples:
|
|
305
425
|
>>> await client.dbsize()
|
|
@@ -313,17 +433,21 @@ class ClusterCommands(CoreCommands):
|
|
|
313
433
|
"""
|
|
314
434
|
Echoes the provided `message` back.
|
|
315
435
|
|
|
316
|
-
See https://valkey.io/commands/echo for more details.
|
|
436
|
+
See [valkey.io](https://valkey.io/commands/echo) for more details.
|
|
317
437
|
|
|
318
438
|
Args:
|
|
319
439
|
message (TEncodable): The message to be echoed back.
|
|
320
440
|
route (Optional[Route]): The command will be routed to a random node, unless `route` is provided,
|
|
321
|
-
|
|
441
|
+
in which case the client will route the command to the nodes defined by `route`.
|
|
322
442
|
|
|
323
443
|
Returns:
|
|
324
444
|
TClusterResponse[bytes]: The provided `message`.
|
|
325
|
-
|
|
326
|
-
|
|
445
|
+
|
|
446
|
+
When specifying a route other than a single node, response will be::
|
|
447
|
+
|
|
448
|
+
{Address (bytes) : response (bytes) , ... }
|
|
449
|
+
|
|
450
|
+
with type of Dict[bytes, bytes].
|
|
327
451
|
|
|
328
452
|
Examples:
|
|
329
453
|
>>> await client.echo(b"Valkey GLIDE")
|
|
@@ -345,7 +469,7 @@ class ClusterCommands(CoreCommands):
|
|
|
345
469
|
"""
|
|
346
470
|
Loads a library to Valkey.
|
|
347
471
|
|
|
348
|
-
See https://valkey.io/commands/function-load/ for more details.
|
|
472
|
+
See [valkey.io](https://valkey.io/commands/function-load/) for more details.
|
|
349
473
|
|
|
350
474
|
Args:
|
|
351
475
|
library_code (TEncodable): The source code that implements the library.
|
|
@@ -358,7 +482,7 @@ class ClusterCommands(CoreCommands):
|
|
|
358
482
|
bytes: The library name that was loaded.
|
|
359
483
|
|
|
360
484
|
Examples:
|
|
361
|
-
>>> code = "#!lua name=mylib
|
|
485
|
+
>>> code = "#!lua name=mylib \\n redis.register_function('myfunc', function(keys, args) return args[1] end)"
|
|
362
486
|
>>> await client.function_load(code, True, RandomNode())
|
|
363
487
|
b"mylib"
|
|
364
488
|
|
|
@@ -382,7 +506,7 @@ class ClusterCommands(CoreCommands):
|
|
|
382
506
|
"""
|
|
383
507
|
Returns information about the functions and libraries.
|
|
384
508
|
|
|
385
|
-
See https://valkey.io/commands/function-list/ for more details.
|
|
509
|
+
See [valkey.io](https://valkey.io/commands/function-list/) for more details.
|
|
386
510
|
|
|
387
511
|
Args:
|
|
388
512
|
library_name_pattern (Optional[TEncodable]): A wildcard pattern for matching library names.
|
|
@@ -404,7 +528,9 @@ class ClusterCommands(CoreCommands):
|
|
|
404
528
|
b"description": None,
|
|
405
529
|
b"flags": {b"no-writes"},
|
|
406
530
|
}],
|
|
407
|
-
b"library_code":
|
|
531
|
+
b"library_code":
|
|
532
|
+
b"#!lua name=mylib \\n redis.register_function('myfunc', function(keys, args) " \\
|
|
533
|
+
b"return args[1] end)"
|
|
408
534
|
}]
|
|
409
535
|
|
|
410
536
|
Since: Valkey 7.0.0.
|
|
@@ -429,7 +555,7 @@ class ClusterCommands(CoreCommands):
|
|
|
429
555
|
"""
|
|
430
556
|
Deletes all function libraries.
|
|
431
557
|
|
|
432
|
-
See https://valkey.io/commands/function-flush/ for more details.
|
|
558
|
+
See [valkey.io](https://valkey.io/commands/function-flush/) for more details.
|
|
433
559
|
|
|
434
560
|
Args:
|
|
435
561
|
mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.
|
|
@@ -460,10 +586,10 @@ class ClusterCommands(CoreCommands):
|
|
|
460
586
|
"""
|
|
461
587
|
Deletes a library and all its functions.
|
|
462
588
|
|
|
463
|
-
See https://valkey.io/commands/function-delete/ for more details.
|
|
589
|
+
See [valkey.io](https://valkey.io/commands/function-delete/) for more details.
|
|
464
590
|
|
|
465
591
|
Args:
|
|
466
|
-
|
|
592
|
+
library_name (TEncodable): The library name to delete
|
|
467
593
|
route (Optional[Route]): The command will be routed to all primaries, unless `route` is provided,
|
|
468
594
|
in which case the client will route the command to the nodes defined by `route`.
|
|
469
595
|
|
|
@@ -490,7 +616,7 @@ class ClusterCommands(CoreCommands):
|
|
|
490
616
|
Kills a function that is currently executing.
|
|
491
617
|
This command only terminates read-only functions.
|
|
492
618
|
|
|
493
|
-
See https://valkey.io/commands/function-kill/ for more details.
|
|
619
|
+
See [valkey.io](https://valkey.io/commands/function-kill/) for more details.
|
|
494
620
|
|
|
495
621
|
Args:
|
|
496
622
|
route (Optional[Route]): The command will be routed to all nodes, unless `route` is provided,
|
|
@@ -522,7 +648,8 @@ class ClusterCommands(CoreCommands):
|
|
|
522
648
|
) -> TClusterResponse[TResult]:
|
|
523
649
|
"""
|
|
524
650
|
Invokes a previously loaded function.
|
|
525
|
-
|
|
651
|
+
|
|
652
|
+
See [valkey.io](https://valkey.io/commands/fcall/) for more details.
|
|
526
653
|
|
|
527
654
|
Args:
|
|
528
655
|
function (TEncodable): The function name.
|
|
@@ -532,13 +659,18 @@ class ClusterCommands(CoreCommands):
|
|
|
532
659
|
case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
533
660
|
|
|
534
661
|
Returns:
|
|
535
|
-
TClusterResponse[TResult]:
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
662
|
+
TClusterResponse[TResult]: If a single node route is requested,
|
|
663
|
+
returns a Optional[TResult] representing the function's return value.
|
|
664
|
+
|
|
665
|
+
Otherwise, returns a dict of [bytes , Optional[TResult]] where each key contains the address of
|
|
666
|
+
the queried node and the value contains the function's return value.
|
|
539
667
|
|
|
540
668
|
Example:
|
|
541
|
-
>>> await client.fcall(
|
|
669
|
+
>>> await client.fcall(
|
|
670
|
+
... "Deep_Thought",
|
|
671
|
+
... ["Answer", "to", "the", "Ultimate", "Question", "of", "Life,", "the", "Universe,", "and", "Everything"],
|
|
672
|
+
... RandomNode()
|
|
673
|
+
... )
|
|
542
674
|
b'new_value' # Returns the function's return value.
|
|
543
675
|
|
|
544
676
|
Since: Valkey version 7.0.0.
|
|
@@ -560,7 +692,7 @@ class ClusterCommands(CoreCommands):
|
|
|
560
692
|
"""
|
|
561
693
|
Invokes a previously loaded read-only function.
|
|
562
694
|
|
|
563
|
-
See https://valkey.io/commands/fcall_ro for more details.
|
|
695
|
+
See [valkey.io](https://valkey.io/commands/fcall_ro) for more details.
|
|
564
696
|
|
|
565
697
|
Args:
|
|
566
698
|
function (TEncodable): The function name.
|
|
@@ -593,17 +725,19 @@ class ClusterCommands(CoreCommands):
|
|
|
593
725
|
Returns information about the function that's currently running and information about the
|
|
594
726
|
available execution engines.
|
|
595
727
|
|
|
596
|
-
See https://valkey.io/commands/function-stats/ for more details
|
|
728
|
+
See [valkey.io](https://valkey.io/commands/function-stats/) for more details
|
|
597
729
|
|
|
598
730
|
Args:
|
|
599
|
-
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
600
|
-
case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
731
|
+
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
732
|
+
which case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
601
733
|
|
|
602
734
|
Returns:
|
|
603
735
|
TClusterResponse[TFunctionStatsSingleNodeResponse]: A `Mapping` with two keys:
|
|
736
|
+
|
|
604
737
|
- `running_script` with information about the running script.
|
|
605
738
|
- `engines` with information about available engines and their stats.
|
|
606
|
-
|
|
739
|
+
|
|
740
|
+
See example for more details.
|
|
607
741
|
|
|
608
742
|
Examples:
|
|
609
743
|
>>> await client.function_stats(RandomNode())
|
|
@@ -634,7 +768,7 @@ class ClusterCommands(CoreCommands):
|
|
|
634
768
|
"""
|
|
635
769
|
Returns the serialized payload of all loaded libraries.
|
|
636
770
|
|
|
637
|
-
See https://valkey.io/commands/function-dump/ for more details.
|
|
771
|
+
See [valkey.io](https://valkey.io/commands/function-dump/) for more details.
|
|
638
772
|
|
|
639
773
|
Args:
|
|
640
774
|
route (Optional[Route]): The command will be routed to a random node, unless
|
|
@@ -667,7 +801,7 @@ class ClusterCommands(CoreCommands):
|
|
|
667
801
|
"""
|
|
668
802
|
Restores libraries from the serialized payload returned by the `function_dump` command.
|
|
669
803
|
|
|
670
|
-
See https://valkey.io/commands/function-restore/ for more details.
|
|
804
|
+
See [valkey.io](https://valkey.io/commands/function-restore/) for more details.
|
|
671
805
|
|
|
672
806
|
Args:
|
|
673
807
|
payload (bytes): The serialized data from the `function_dump` command.
|
|
@@ -704,24 +838,32 @@ class ClusterCommands(CoreCommands):
|
|
|
704
838
|
"""
|
|
705
839
|
Returns the server time.
|
|
706
840
|
|
|
707
|
-
See https://valkey.io/commands/time/ for more details.
|
|
841
|
+
See [valkey.io](https://valkey.io/commands/time/) for more details.
|
|
708
842
|
|
|
709
843
|
Args:
|
|
710
844
|
route (Optional[Route]): The command will be routed to a random node, unless `route` is provided,
|
|
711
|
-
|
|
845
|
+
in which case the client will route the command to the nodes defined by `route`.
|
|
712
846
|
|
|
713
847
|
Returns:
|
|
714
848
|
TClusterResponse[Optional[bytes]]: The current server time as a two items `array`:
|
|
715
849
|
A Unix timestamp and the amount of microseconds already elapsed in the current second.
|
|
716
850
|
The returned `array` is in a [Unix timestamp, Microseconds already elapsed] format.
|
|
717
|
-
|
|
718
|
-
|
|
851
|
+
|
|
852
|
+
When specifying a route other than a single node, response will be::
|
|
853
|
+
|
|
854
|
+
{Address (bytes) : response (List[bytes]) , ... }
|
|
855
|
+
|
|
856
|
+
with type of Dict[bytes, List[bytes]].
|
|
719
857
|
|
|
720
858
|
Examples:
|
|
721
859
|
>>> await client.time()
|
|
722
860
|
[b'1710925775', b'913580']
|
|
723
861
|
>>> await client.time(AllNodes())
|
|
724
|
-
{
|
|
862
|
+
{
|
|
863
|
+
b'addr': [b'1710925775', b'913580'],
|
|
864
|
+
b'addr2': [b'1710925775', b'913580'],
|
|
865
|
+
b'addr3': [b'1710925775', b'913580']
|
|
866
|
+
}
|
|
725
867
|
"""
|
|
726
868
|
return cast(
|
|
727
869
|
TClusterResponse[List[bytes]],
|
|
@@ -732,7 +874,7 @@ class ClusterCommands(CoreCommands):
|
|
|
732
874
|
"""
|
|
733
875
|
Returns the Unix time of the last DB save timestamp or startup timestamp if no save was made since then.
|
|
734
876
|
|
|
735
|
-
See https://valkey.io/commands/lastsave for more details.
|
|
877
|
+
See [valkey.io](https://valkey.io/commands/lastsave) for more details.
|
|
736
878
|
|
|
737
879
|
Args:
|
|
738
880
|
route (Optional[Route]): The command will be routed to a random node, unless `route` is provided,
|
|
@@ -740,15 +882,19 @@ class ClusterCommands(CoreCommands):
|
|
|
740
882
|
|
|
741
883
|
Returns:
|
|
742
884
|
TClusterResponse[int]: The Unix time of the last successful DB save.
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
885
|
+
|
|
886
|
+
If no route is provided, or a single node route is requested, returns an int representing the Unix time
|
|
887
|
+
of the last successful DB save.
|
|
888
|
+
|
|
889
|
+
Otherwise, returns a dict of [bytes , int] where each key contains the
|
|
890
|
+
address of the queried node and the value contains the Unix time of the last successful DB save.
|
|
746
891
|
|
|
747
892
|
Examples:
|
|
748
893
|
>>> await client.lastsave()
|
|
749
894
|
1710925775 # Unix time of the last DB save
|
|
750
895
|
>>> await client.lastsave(AllNodes())
|
|
751
|
-
{b'addr1': 1710925775, b'addr2': 1710925775, b'addr3': 1710925775} # Unix time of the last DB save on
|
|
896
|
+
{b'addr1': 1710925775, b'addr2': 1710925775, b'addr3': 1710925775} # Unix time of the last DB save on
|
|
897
|
+
# each node
|
|
752
898
|
"""
|
|
753
899
|
return cast(
|
|
754
900
|
TClusterResponse[int],
|
|
@@ -766,7 +912,9 @@ class ClusterCommands(CoreCommands):
|
|
|
766
912
|
This command aggregates PUBLISH and SPUBLISH commands functionalities.
|
|
767
913
|
The mode is selected using the 'sharded' parameter.
|
|
768
914
|
For both sharded and non-sharded mode, request is routed using hashed channel as key.
|
|
769
|
-
|
|
915
|
+
|
|
916
|
+
See [PUBLISH](https://valkey.io/commands/publish) and [SPUBLISH](https://valkey.io/commands/spublish)
|
|
917
|
+
for more details.
|
|
770
918
|
|
|
771
919
|
Args:
|
|
772
920
|
message (TEncodable): Message to publish.
|
|
@@ -794,15 +942,15 @@ class ClusterCommands(CoreCommands):
|
|
|
794
942
|
Lists the currently active shard channels.
|
|
795
943
|
The command is routed to all nodes, and aggregates the response to a single array.
|
|
796
944
|
|
|
797
|
-
See https://valkey.io/commands/pubsub-shardchannels for more details.
|
|
945
|
+
See [valkey.io](https://valkey.io/commands/pubsub-shardchannels) for more details.
|
|
798
946
|
|
|
799
947
|
Args:
|
|
800
948
|
pattern (Optional[TEncodable]): A glob-style pattern to match active shard channels.
|
|
801
|
-
|
|
949
|
+
If not provided, all active shard channels are returned.
|
|
802
950
|
|
|
803
951
|
Returns:
|
|
804
952
|
List[bytes]: A list of currently active shard channels matching the given pattern.
|
|
805
|
-
|
|
953
|
+
If no pattern is specified, all active shard channels are returned.
|
|
806
954
|
|
|
807
955
|
Examples:
|
|
808
956
|
>>> await client.pubsub_shardchannels()
|
|
@@ -824,13 +972,14 @@ class ClusterCommands(CoreCommands):
|
|
|
824
972
|
Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified shard channels.
|
|
825
973
|
|
|
826
974
|
Note that it is valid to call this command without channels. In this case, it will just return an empty map.
|
|
827
|
-
The command is routed to all nodes, and aggregates the response to a single map of the channels and their number of
|
|
975
|
+
The command is routed to all nodes, and aggregates the response to a single map of the channels and their number of
|
|
976
|
+
subscriptions.
|
|
828
977
|
|
|
829
|
-
See https://valkey.io/commands/pubsub-shardnumsub for more details.
|
|
978
|
+
See [valkey.io](https://valkey.io/commands/pubsub-shardnumsub) for more details.
|
|
830
979
|
|
|
831
980
|
Args:
|
|
832
981
|
channels (Optional[List[TEncodable]]): The list of shard channels to query for the number of subscribers.
|
|
833
|
-
|
|
982
|
+
If not provided, returns an empty map.
|
|
834
983
|
|
|
835
984
|
Returns:
|
|
836
985
|
Mapping[bytes, int]: A map where keys are the shard channel names and values are the number of subscribers.
|
|
@@ -855,7 +1004,7 @@ class ClusterCommands(CoreCommands):
|
|
|
855
1004
|
"""
|
|
856
1005
|
Deletes all the keys of all the existing databases. This command never fails.
|
|
857
1006
|
|
|
858
|
-
See https://valkey.io/commands/flushall for more details.
|
|
1007
|
+
See [valkey.io](https://valkey.io/commands/flushall) for more details.
|
|
859
1008
|
|
|
860
1009
|
Args:
|
|
861
1010
|
flush_mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.
|
|
@@ -886,7 +1035,7 @@ class ClusterCommands(CoreCommands):
|
|
|
886
1035
|
"""
|
|
887
1036
|
Deletes all the keys of the currently selected database. This command never fails.
|
|
888
1037
|
|
|
889
|
-
See https://valkey.io/commands/flushdb for more details.
|
|
1038
|
+
See [valkey.io](https://valkey.io/commands/flushdb) for more details.
|
|
890
1039
|
|
|
891
1040
|
Args:
|
|
892
1041
|
flush_mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.
|
|
@@ -917,13 +1066,19 @@ class ClusterCommands(CoreCommands):
|
|
|
917
1066
|
self,
|
|
918
1067
|
source: TEncodable,
|
|
919
1068
|
destination: TEncodable,
|
|
1069
|
+
# TODO next major release the arguments replace and destinationDB must have their order
|
|
1070
|
+
# swapped to align with the standalone order.
|
|
1071
|
+
# At the moment of the patch release 2.1.1. we can't have a breaking change
|
|
920
1072
|
replace: Optional[bool] = None,
|
|
1073
|
+
destinationDB: Optional[int] = None,
|
|
921
1074
|
) -> bool:
|
|
922
1075
|
"""
|
|
923
|
-
Copies the value stored at the `source` to the `destination` key.
|
|
924
|
-
|
|
1076
|
+
Copies the value stored at the `source` to the `destination` key. If `destinationDB`
|
|
1077
|
+
is specified, the value will be copied to the database specified by `destinationDB`,
|
|
1078
|
+
otherwise the current database will be used. When `replace` is True, removes the
|
|
1079
|
+
`destination` key first if it already exists, otherwise performs no action.
|
|
925
1080
|
|
|
926
|
-
See https://valkey.io/commands/copy for more details.
|
|
1081
|
+
See [valkey.io](https://valkey.io/commands/copy) for more details.
|
|
927
1082
|
|
|
928
1083
|
Note:
|
|
929
1084
|
Both `source` and `destination` must map to the same hash slot.
|
|
@@ -932,6 +1087,7 @@ class ClusterCommands(CoreCommands):
|
|
|
932
1087
|
source (TEncodable): The key to the source value.
|
|
933
1088
|
destination (TEncodable): The key where the value should be copied to.
|
|
934
1089
|
replace (Optional[bool]): If the destination key should be removed before copying the value to it.
|
|
1090
|
+
destinationDB (Optional[int]): The alternative logical database index for the destination key.
|
|
935
1091
|
|
|
936
1092
|
Returns:
|
|
937
1093
|
bool: True if the source was copied. Otherwise, returns False.
|
|
@@ -940,12 +1096,20 @@ class ClusterCommands(CoreCommands):
|
|
|
940
1096
|
>>> await client.set("source", "sheep")
|
|
941
1097
|
>>> await client.copy(b"source", b"destination")
|
|
942
1098
|
True # Source was copied
|
|
1099
|
+
>>> await client.copy(b"source", b"destination", destinationDB=1)
|
|
1100
|
+
True # Source was copied to DB 1
|
|
1101
|
+
>>> await client.select(1)
|
|
943
1102
|
>>> await client.get("destination")
|
|
944
1103
|
b"sheep"
|
|
945
1104
|
|
|
946
1105
|
Since: Valkey version 6.2.0.
|
|
1106
|
+
The destinationDB argument is available since Valkey 9.0.0
|
|
947
1107
|
"""
|
|
1108
|
+
|
|
1109
|
+
# Build command arguments
|
|
948
1110
|
args: List[TEncodable] = [source, destination]
|
|
1111
|
+
if destinationDB is not None:
|
|
1112
|
+
args.extend(["DB", str(destinationDB)])
|
|
949
1113
|
if replace is True:
|
|
950
1114
|
args.append("REPLACE")
|
|
951
1115
|
return cast(
|
|
@@ -962,20 +1126,26 @@ class ClusterCommands(CoreCommands):
|
|
|
962
1126
|
"""
|
|
963
1127
|
Displays a piece of generative computer art and the Valkey version.
|
|
964
1128
|
|
|
965
|
-
See https://valkey.io/commands/lolwut for more details.
|
|
1129
|
+
See [valkey.io](https://valkey.io/commands/lolwut) for more details.
|
|
966
1130
|
|
|
967
1131
|
Args:
|
|
968
1132
|
version (Optional[int]): Version of computer art to generate.
|
|
969
1133
|
parameters (Optional[List[int]]): Additional set of arguments in order to change the output:
|
|
970
|
-
|
|
971
|
-
For version `
|
|
1134
|
+
|
|
1135
|
+
- For version `5`, those are length of the line, number of squares per row, and number of squares per column.
|
|
1136
|
+
- For version `6`, those are number of columns and number of lines.
|
|
1137
|
+
|
|
972
1138
|
route (Optional[Route]): The command will be routed to a random node, unless `route` is provided,
|
|
973
1139
|
in which case the client will route the command to the nodes defined by `route`.
|
|
974
1140
|
|
|
975
1141
|
Returns:
|
|
976
1142
|
TClusterResponse[bytes]: A piece of generative computer art along with the current Valkey version.
|
|
977
|
-
|
|
978
|
-
|
|
1143
|
+
|
|
1144
|
+
When specifying a route other than a single node, response will be::
|
|
1145
|
+
|
|
1146
|
+
{Address (bytes) : response (bytes) , ... }
|
|
1147
|
+
|
|
1148
|
+
with type of Dict[bytes, bytes].
|
|
979
1149
|
|
|
980
1150
|
Examples:
|
|
981
1151
|
>>> await client.lolwut(6, [40, 20], RandomNode());
|
|
@@ -986,7 +1156,7 @@ class ClusterCommands(CoreCommands):
|
|
|
986
1156
|
args.extend(["VERSION", str(version)])
|
|
987
1157
|
if parameters:
|
|
988
1158
|
for var in parameters:
|
|
989
|
-
args.
|
|
1159
|
+
args.append(str(var))
|
|
990
1160
|
return cast(
|
|
991
1161
|
TClusterResponse[bytes],
|
|
992
1162
|
await self._execute_command(RequestType.Lolwut, args, route),
|
|
@@ -996,7 +1166,7 @@ class ClusterCommands(CoreCommands):
|
|
|
996
1166
|
"""
|
|
997
1167
|
Returns a random existing key name.
|
|
998
1168
|
|
|
999
|
-
See https://valkey.io/commands/randomkey for more details.
|
|
1169
|
+
See [valkey.io](https://valkey.io/commands/randomkey) for more details.
|
|
1000
1170
|
|
|
1001
1171
|
Args:
|
|
1002
1172
|
route (Optional[Route]): The command will be routed to all primary nodes, unless `route` is provided,
|
|
@@ -1025,13 +1195,13 @@ class ClusterCommands(CoreCommands):
|
|
|
1025
1195
|
and acknowledged by at least `numreplicas` of replicas. If `timeout` is
|
|
1026
1196
|
reached, the command returns even if the specified number of replicas were not yet reached.
|
|
1027
1197
|
|
|
1028
|
-
See https://valkey.io/commands/wait for more details.
|
|
1198
|
+
See [valkey.io](https://valkey.io/commands/wait) for more details.
|
|
1029
1199
|
|
|
1030
1200
|
Args:
|
|
1031
1201
|
numreplicas (int): The number of replicas to reach.
|
|
1032
1202
|
timeout (int): The timeout value specified in milliseconds. A value of 0 will block indefinitely.
|
|
1033
1203
|
route (Optional[Route]): The command will be routed to all primary nodes, unless `route` is provided,
|
|
1034
|
-
|
|
1204
|
+
in which case the client will route the command to the nodes defined by `route`.
|
|
1035
1205
|
|
|
1036
1206
|
Returns:
|
|
1037
1207
|
int: The number of replicas reached by all the writes performed in the context of the current connection.
|
|
@@ -1039,7 +1209,7 @@ class ClusterCommands(CoreCommands):
|
|
|
1039
1209
|
Examples:
|
|
1040
1210
|
>>> await client.set("key", "value");
|
|
1041
1211
|
>>> await client.wait(1, 1000);
|
|
1042
|
-
|
|
1212
|
+
# return 1 when a replica is reached or 0 if 1000ms is reached.
|
|
1043
1213
|
"""
|
|
1044
1214
|
args: List[TEncodable] = [str(numreplicas), str(timeout)]
|
|
1045
1215
|
return cast(
|
|
@@ -1052,7 +1222,7 @@ class ClusterCommands(CoreCommands):
|
|
|
1052
1222
|
Flushes all the previously watched keys for a transaction. Executing a transaction will
|
|
1053
1223
|
automatically flush all previously watched keys.
|
|
1054
1224
|
|
|
1055
|
-
See https://valkey.io/commands/unwatch for more details.
|
|
1225
|
+
See [valkey.io](https://valkey.io/commands/unwatch) for more details.
|
|
1056
1226
|
|
|
1057
1227
|
Args:
|
|
1058
1228
|
route (Optional[Route]): The command will be routed to all primary nodes, unless `route` is provided,
|
|
@@ -1076,67 +1246,87 @@ class ClusterCommands(CoreCommands):
|
|
|
1076
1246
|
match: Optional[TEncodable] = None,
|
|
1077
1247
|
count: Optional[int] = None,
|
|
1078
1248
|
type: Optional[ObjectType] = None,
|
|
1249
|
+
allow_non_covered_slots: bool = False,
|
|
1079
1250
|
) -> List[Union[ClusterScanCursor, List[bytes]]]:
|
|
1080
1251
|
"""
|
|
1081
|
-
Incrementally iterates over the keys in the
|
|
1252
|
+
Incrementally iterates over the keys in the cluster.
|
|
1082
1253
|
The method returns a list containing the next cursor and a list of keys.
|
|
1083
1254
|
|
|
1084
|
-
This command is similar to the SCAN command
|
|
1085
|
-
For each iteration the new cursor object should be used to continue the scan.
|
|
1255
|
+
This command is similar to the SCAN command but is designed to work in a cluster environment.
|
|
1256
|
+
For each iteration, the new cursor object should be used to continue the scan.
|
|
1086
1257
|
Using the same cursor object for multiple iterations will result in the same keys or unexpected behavior.
|
|
1087
|
-
For more information about the Cluster Scan implementation,
|
|
1088
|
-
|
|
1258
|
+
For more information about the Cluster Scan implementation, see
|
|
1259
|
+
[Cluster Scan](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#cluster-scan).
|
|
1089
1260
|
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
The same key can be returned in multiple
|
|
1261
|
+
Like the SCAN command, the method can be used to iterate over the keys in the database,
|
|
1262
|
+
returning all keys the database has from when the scan started until the scan ends.
|
|
1263
|
+
The same key can be returned in multiple scan iterations.
|
|
1093
1264
|
|
|
1094
|
-
See https://valkey.io/commands/scan/ for more details.
|
|
1265
|
+
See [valkey.io](https://valkey.io/commands/scan/) for more details.
|
|
1095
1266
|
|
|
1096
1267
|
Args:
|
|
1097
1268
|
cursor (ClusterScanCursor): The cursor object that wraps the scan state.
|
|
1098
|
-
|
|
1269
|
+
To start a new scan, create a new empty ClusterScanCursor using ClusterScanCursor().
|
|
1099
1270
|
match (Optional[TEncodable]): A pattern to match keys against.
|
|
1100
1271
|
count (Optional[int]): The number of keys to return in a single iteration.
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1272
|
+
The actual number returned can vary and is not guaranteed to match this count exactly.
|
|
1273
|
+
This parameter serves as a hint to the server on the number of steps to perform in each iteration.
|
|
1274
|
+
The default value is 10.
|
|
1104
1275
|
type (Optional[ObjectType]): The type of object to scan for.
|
|
1276
|
+
allow_non_covered_slots (bool): If set to True, the scan will perform even if some slots are not covered by any
|
|
1277
|
+
node.
|
|
1278
|
+
It's important to note that when set to True, the scan has no guarantee to cover all keys in the cluster,
|
|
1279
|
+
and the method loses its way to validate the progress of the scan. Defaults to False.
|
|
1105
1280
|
|
|
1106
1281
|
Returns:
|
|
1107
1282
|
List[Union[ClusterScanCursor, List[TEncodable]]]: A list containing the next cursor and a list of keys,
|
|
1108
|
-
|
|
1283
|
+
formatted as [ClusterScanCursor, [key1, key2, ...]].
|
|
1109
1284
|
|
|
1110
1285
|
Examples:
|
|
1111
|
-
>>> #
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1286
|
+
>>> # Iterate over all keys in the cluster.
|
|
1287
|
+
>>> await client.mset({b'key1': b'value1', b'key2': b'value2', b'key3': b'value3'})
|
|
1288
|
+
>>> cursor = ClusterScanCursor()
|
|
1289
|
+
>>> all_keys = []
|
|
1290
|
+
>>> while not cursor.is_finished():
|
|
1291
|
+
>>> cursor, keys = await client.scan(cursor, count=10, allow_non_covered_slots=False)
|
|
1292
|
+
>>> all_keys.extend(keys)
|
|
1293
|
+
>>> print(all_keys) # [b'key1', b'key2', b'key3']
|
|
1294
|
+
|
|
1295
|
+
>>> # Iterate over keys matching the pattern "*key*".
|
|
1296
|
+
>>> await client.mset(
|
|
1297
|
+
... {
|
|
1298
|
+
... b"key1": b"value1",
|
|
1299
|
+
... b"key2": b"value2",
|
|
1300
|
+
... b"not_my_key": b"value3",
|
|
1301
|
+
... b"something_else": b"value4"
|
|
1302
|
+
... }
|
|
1303
|
+
... )
|
|
1304
|
+
>>> cursor = ClusterScanCursor()
|
|
1305
|
+
>>> all_keys = []
|
|
1306
|
+
>>> while not cursor.is_finished():
|
|
1307
|
+
>>> cursor, keys = await client.scan(cursor, match=b"*key*", count=10, allow_non_covered_slots=False)
|
|
1308
|
+
>>> all_keys.extend(keys)
|
|
1309
|
+
>>> print(all_keys) # [b'key1', b'key2', b'not_my_key']
|
|
1310
|
+
|
|
1311
|
+
>>> # Iterate over keys of type STRING.
|
|
1312
|
+
>>> await client.mset({b'key1': b'value1', b'key2': b'value2', b'key3': b'value3'})
|
|
1313
|
+
>>> await client.sadd(b"this_is_a_set", [b"value4"])
|
|
1314
|
+
>>> cursor = ClusterScanCursor()
|
|
1315
|
+
>>> all_keys = []
|
|
1316
|
+
>>> while not cursor.is_finished():
|
|
1317
|
+
>>> cursor, keys = await client.scan(cursor, type=ObjectType.STRING, allow_non_covered_slots=False)
|
|
1318
|
+
>>> all_keys.extend(keys)
|
|
1319
|
+
>>> print(all_keys) # [b'key1', b'key2', b'key3']
|
|
1136
1320
|
"""
|
|
1137
1321
|
return cast(
|
|
1138
1322
|
List[Union[ClusterScanCursor, List[bytes]]],
|
|
1139
|
-
await self._cluster_scan(
|
|
1323
|
+
await self._cluster_scan(
|
|
1324
|
+
cursor=cursor,
|
|
1325
|
+
match=match,
|
|
1326
|
+
count=count,
|
|
1327
|
+
type=type,
|
|
1328
|
+
allow_non_covered_slots=allow_non_covered_slots,
|
|
1329
|
+
),
|
|
1140
1330
|
)
|
|
1141
1331
|
|
|
1142
1332
|
async def script_exists(
|
|
@@ -1145,7 +1335,7 @@ class ClusterCommands(CoreCommands):
|
|
|
1145
1335
|
"""
|
|
1146
1336
|
Check existence of scripts in the script cache by their SHA1 digest.
|
|
1147
1337
|
|
|
1148
|
-
See https://valkey.io/commands/script-exists for more details.
|
|
1338
|
+
See [valkey.io](https://valkey.io/commands/script-exists) for more details.
|
|
1149
1339
|
|
|
1150
1340
|
Args:
|
|
1151
1341
|
sha1s (List[TEncodable]): List of SHA1 digests of the scripts to check.
|
|
@@ -1171,12 +1361,12 @@ class ClusterCommands(CoreCommands):
|
|
|
1171
1361
|
"""
|
|
1172
1362
|
Flush the Lua scripts cache.
|
|
1173
1363
|
|
|
1174
|
-
See https://valkey.io/commands/script-flush for more details.
|
|
1364
|
+
See [valkey.io](https://valkey.io/commands/script-flush) for more details.
|
|
1175
1365
|
|
|
1176
1366
|
Args:
|
|
1177
1367
|
mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.
|
|
1178
|
-
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
1179
|
-
case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
1368
|
+
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
1369
|
+
which case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
1180
1370
|
|
|
1181
1371
|
Returns:
|
|
1182
1372
|
TOK: A simple `OK` response.
|
|
@@ -1201,12 +1391,14 @@ class ClusterCommands(CoreCommands):
|
|
|
1201
1391
|
Kill the currently executing Lua script, assuming no write operation was yet performed by the script.
|
|
1202
1392
|
The command is routed to all nodes, and aggregates the response to a single array.
|
|
1203
1393
|
|
|
1204
|
-
See https://valkey.io/commands/script-kill for more details.
|
|
1394
|
+
See [valkey.io](https://valkey.io/commands/script-kill) for more details.
|
|
1395
|
+
|
|
1396
|
+
Args:
|
|
1397
|
+
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in
|
|
1398
|
+
which case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
1205
1399
|
|
|
1206
1400
|
Returns:
|
|
1207
1401
|
TOK: A simple `OK` response.
|
|
1208
|
-
route (Optional[Route]): The command will be routed automatically to all nodes, unless `route` is provided, in which
|
|
1209
|
-
case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
1210
1402
|
|
|
1211
1403
|
Examples:
|
|
1212
1404
|
>>> await client.script_kill()
|
|
@@ -1227,9 +1419,11 @@ class ClusterCommands(CoreCommands):
|
|
|
1227
1419
|
If the script has not already been loaded, it will be loaded automatically using the `SCRIPT LOAD` command.
|
|
1228
1420
|
After that, it will be invoked using the `EVALSHA` command.
|
|
1229
1421
|
|
|
1230
|
-
|
|
1422
|
+
Note:
|
|
1423
|
+
When in cluster mode, each `key` must map to the same hash slot.
|
|
1231
1424
|
|
|
1232
|
-
See https://valkey.io/commands/script-load/ and https://valkey.io/commands/evalsha/
|
|
1425
|
+
See [SCRIPT LOAD](https://valkey.io/commands/script-load/) and [EVALSHA](https://valkey.io/commands/evalsha/)
|
|
1426
|
+
for more details.
|
|
1233
1427
|
|
|
1234
1428
|
Args:
|
|
1235
1429
|
script (Script): The Lua script to execute.
|
|
@@ -1242,7 +1436,7 @@ class ClusterCommands(CoreCommands):
|
|
|
1242
1436
|
|
|
1243
1437
|
Examples:
|
|
1244
1438
|
>>> lua_script = Script("return { KEYS[1], ARGV[1] }")
|
|
1245
|
-
>>> await invoke_script(lua_script, keys=["foo"], args=["bar"]
|
|
1439
|
+
>>> await client.invoke_script(lua_script, keys=["foo"], args=["bar"])
|
|
1246
1440
|
[b"foo", b"bar"]
|
|
1247
1441
|
"""
|
|
1248
1442
|
return await self._execute_script(script.get_hash(), keys, args)
|
|
@@ -1260,20 +1454,21 @@ class ClusterCommands(CoreCommands):
|
|
|
1260
1454
|
If the script has not already been loaded, it will be loaded automatically using the `SCRIPT LOAD` command.
|
|
1261
1455
|
After that, it will be invoked using the `EVALSHA` command.
|
|
1262
1456
|
|
|
1263
|
-
See https://valkey.io/commands/script-load/ and https://valkey.io/commands/evalsha/
|
|
1457
|
+
See [SCRIPT LOAD](https://valkey.io/commands/script-load/) and [EVALSHA](https://valkey.io/commands/evalsha/)
|
|
1458
|
+
for more details.
|
|
1264
1459
|
|
|
1265
1460
|
Args:
|
|
1266
1461
|
script (Script): The Lua script to execute.
|
|
1267
1462
|
args (Optional[List[TEncodable]]): The non-key arguments for the script.
|
|
1268
|
-
route (Optional[Route]): The command will be routed automatically to a random node, unless `route` is provided, in
|
|
1269
|
-
case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
1463
|
+
route (Optional[Route]): The command will be routed automatically to a random node, unless `route` is provided, in
|
|
1464
|
+
which case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
1270
1465
|
|
|
1271
1466
|
Returns:
|
|
1272
1467
|
TResult: a value that depends on the script that was executed.
|
|
1273
1468
|
|
|
1274
1469
|
Examples:
|
|
1275
1470
|
>>> lua_script = Script("return { ARGV[1] }")
|
|
1276
|
-
>>> await invoke_script(lua_script, args=["bar"], route=AllPrimaries());
|
|
1471
|
+
>>> await client.invoke_script(lua_script, args=["bar"], route=AllPrimaries());
|
|
1277
1472
|
[b"bar"]
|
|
1278
1473
|
"""
|
|
1279
1474
|
return await self._execute_script(
|