valkey-glide 2.0.0rc7__cp312-cp312-macosx_10_7_x86_64.whl → 2.1.0rc1__cp312-cp312-macosx_10_7_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of valkey-glide might be problematic. Click here for more details.
- glide/__init__.py +103 -107
- glide/async_commands/cluster_commands.py +83 -101
- glide/async_commands/core.py +554 -424
- glide/async_commands/{server_modules/ft.py → ft.py} +8 -7
- glide/async_commands/{server_modules/glide_json.py → glide_json.py} +15 -92
- glide/async_commands/standalone_commands.py +18 -17
- glide/glide.cpython-312-darwin.so +0 -0
- glide/glide.pyi +26 -1
- glide/glide_client.py +70 -45
- glide/logger.py +33 -21
- glide/opentelemetry.py +185 -0
- glide_shared/__init__.py +326 -0
- {glide/async_commands → glide_shared/commands}/batch.py +411 -18
- glide_shared/commands/batch_options.py +261 -0
- glide_shared/commands/core_options.py +407 -0
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +3 -3
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +4 -2
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +4 -4
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +4 -2
- {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +4 -4
- glide_shared/commands/server_modules/json_options.py +93 -0
- {glide/async_commands → glide_shared/commands}/sorted_set.py +2 -2
- {glide/async_commands → glide_shared/commands}/stream.py +1 -1
- {glide → glide_shared}/config.py +120 -32
- {glide → glide_shared}/constants.py +3 -3
- {glide → glide_shared}/exceptions.py +27 -1
- glide_shared/protobuf/command_request_pb2.py +54 -0
- glide_shared/protobuf/connection_request_pb2.py +52 -0
- {glide → glide_shared}/protobuf/response_pb2.py +6 -6
- {glide → glide_shared}/routes.py +29 -15
- valkey_glide-2.1.0rc1.dist-info/METADATA +210 -0
- valkey_glide-2.1.0rc1.dist-info/RECORD +39 -0
- glide/protobuf/command_request_pb2.py +0 -54
- glide/protobuf/command_request_pb2.pyi +0 -1187
- glide/protobuf/connection_request_pb2.py +0 -54
- glide/protobuf/connection_request_pb2.pyi +0 -320
- glide/protobuf/response_pb2.pyi +0 -100
- valkey_glide-2.0.0rc7.dist-info/METADATA +0 -144
- valkey_glide-2.0.0rc7.dist-info/RECORD +0 -37
- /glide/py.typed → /glide_shared/commands/__init__.py +0 -0
- {glide/async_commands → glide_shared/commands}/bitmap.py +0 -0
- {glide/async_commands → glide_shared/commands}/command_args.py +0 -0
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
- {glide → glide_shared}/protobuf_codec.py +0 -0
- {valkey_glide-2.0.0rc7.dist-info → valkey_glide-2.1.0rc1.dist-info}/WHEEL +0 -0
glide/__init__.py
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
2
|
|
|
3
|
-
from glide.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
from glide.glide import (
|
|
4
|
+
ClusterScanCursor,
|
|
5
|
+
OpenTelemetryConfig,
|
|
6
|
+
OpenTelemetryMetricsConfig,
|
|
7
|
+
OpenTelemetryTracesConfig,
|
|
8
|
+
Script,
|
|
9
9
|
)
|
|
10
|
-
from
|
|
10
|
+
from glide_shared import (
|
|
11
|
+
OK,
|
|
12
|
+
TOK,
|
|
13
|
+
AdvancedGlideClientConfiguration,
|
|
14
|
+
AdvancedGlideClusterClientConfiguration,
|
|
15
|
+
AggregationType,
|
|
16
|
+
AllNodes,
|
|
17
|
+
AllPrimaries,
|
|
18
|
+
BackoffStrategy,
|
|
19
|
+
Batch,
|
|
20
|
+
BatchOptions,
|
|
21
|
+
BatchRetryStrategy,
|
|
11
22
|
BitEncoding,
|
|
12
23
|
BitFieldGet,
|
|
13
24
|
BitFieldIncrBy,
|
|
@@ -20,28 +31,26 @@ from glide.async_commands.bitmap import (
|
|
|
20
31
|
BitOffsetMultiplier,
|
|
21
32
|
BitOverflowControl,
|
|
22
33
|
BitwiseOperation,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
from glide.async_commands.core import (
|
|
34
|
+
ByAddressRoute,
|
|
35
|
+
ClosingError,
|
|
36
|
+
ClusterBatch,
|
|
37
|
+
ClusterBatchOptions,
|
|
38
|
+
ClusterTransaction,
|
|
29
39
|
ConditionalChange,
|
|
30
|
-
|
|
40
|
+
ConfigurationError,
|
|
41
|
+
ConnectionError,
|
|
42
|
+
DataType,
|
|
43
|
+
DistanceMetricType,
|
|
44
|
+
ExclusiveIdBound,
|
|
45
|
+
ExecAbortError,
|
|
31
46
|
ExpireOptions,
|
|
32
47
|
ExpiryGetEx,
|
|
33
48
|
ExpirySet,
|
|
34
49
|
ExpiryType,
|
|
35
50
|
ExpiryTypeGetEx,
|
|
51
|
+
Field,
|
|
52
|
+
FieldType,
|
|
36
53
|
FlushMode,
|
|
37
|
-
FunctionRestorePolicy,
|
|
38
|
-
InfoSection,
|
|
39
|
-
InsertPosition,
|
|
40
|
-
OnlyIfEqual,
|
|
41
|
-
UpdateOptions,
|
|
42
|
-
)
|
|
43
|
-
from glide.async_commands.server_modules import ft, glide_json, json_batch
|
|
44
|
-
from glide.async_commands.server_modules.ft_options.ft_aggregate_options import (
|
|
45
54
|
FtAggregateApply,
|
|
46
55
|
FtAggregateClause,
|
|
47
56
|
FtAggregateFilter,
|
|
@@ -49,59 +58,64 @@ from glide.async_commands.server_modules.ft_options.ft_aggregate_options import
|
|
|
49
58
|
FtAggregateLimit,
|
|
50
59
|
FtAggregateOptions,
|
|
51
60
|
FtAggregateReducer,
|
|
61
|
+
FtAggregateResponse,
|
|
52
62
|
FtAggregateSortBy,
|
|
53
63
|
FtAggregateSortProperty,
|
|
54
|
-
)
|
|
55
|
-
from glide.async_commands.server_modules.ft_options.ft_create_options import (
|
|
56
|
-
DataType,
|
|
57
|
-
DistanceMetricType,
|
|
58
|
-
Field,
|
|
59
|
-
FieldType,
|
|
60
64
|
FtCreateOptions,
|
|
61
|
-
|
|
62
|
-
TagField,
|
|
63
|
-
TextField,
|
|
64
|
-
VectorAlgorithm,
|
|
65
|
-
VectorField,
|
|
66
|
-
VectorFieldAttributes,
|
|
67
|
-
VectorFieldAttributesFlat,
|
|
68
|
-
VectorFieldAttributesHnsw,
|
|
69
|
-
VectorType,
|
|
70
|
-
)
|
|
71
|
-
from glide.async_commands.server_modules.ft_options.ft_profile_options import (
|
|
65
|
+
FtInfoResponse,
|
|
72
66
|
FtProfileOptions,
|
|
73
|
-
|
|
74
|
-
)
|
|
75
|
-
from glide.async_commands.server_modules.ft_options.ft_search_options import (
|
|
67
|
+
FtProfileResponse,
|
|
76
68
|
FtSearchLimit,
|
|
77
69
|
FtSearchOptions,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
from glide.async_commands.server_modules.glide_json import (
|
|
81
|
-
JsonArrIndexOptions,
|
|
82
|
-
JsonArrPopOptions,
|
|
83
|
-
JsonGetOptions,
|
|
84
|
-
)
|
|
85
|
-
from glide.async_commands.sorted_set import (
|
|
86
|
-
AggregationType,
|
|
70
|
+
FtSearchResponse,
|
|
71
|
+
FunctionRestorePolicy,
|
|
87
72
|
GeoSearchByBox,
|
|
88
73
|
GeoSearchByRadius,
|
|
89
74
|
GeoSearchCount,
|
|
90
75
|
GeospatialData,
|
|
91
76
|
GeoUnit,
|
|
77
|
+
GlideClientConfiguration,
|
|
78
|
+
GlideClusterClientConfiguration,
|
|
79
|
+
GlideError,
|
|
80
|
+
HashFieldConditionalChange,
|
|
81
|
+
IdBound,
|
|
92
82
|
InfBound,
|
|
83
|
+
InfoSection,
|
|
84
|
+
InsertPosition,
|
|
85
|
+
JsonArrIndexOptions,
|
|
86
|
+
JsonArrPopOptions,
|
|
87
|
+
JsonGetOptions,
|
|
93
88
|
LexBoundary,
|
|
89
|
+
Limit,
|
|
90
|
+
ListDirection,
|
|
91
|
+
MaxId,
|
|
92
|
+
MinId,
|
|
93
|
+
NodeAddress,
|
|
94
|
+
NumericField,
|
|
95
|
+
ObjectType,
|
|
96
|
+
OffsetOptions,
|
|
97
|
+
OnlyIfEqual,
|
|
98
|
+
OrderBy,
|
|
99
|
+
PeriodicChecksManualInterval,
|
|
100
|
+
PeriodicChecksStatus,
|
|
101
|
+
ProtocolVersion,
|
|
102
|
+
PubSubMsg,
|
|
103
|
+
QueryType,
|
|
104
|
+
RandomNode,
|
|
94
105
|
RangeByIndex,
|
|
95
106
|
RangeByLex,
|
|
96
107
|
RangeByScore,
|
|
108
|
+
ReadFrom,
|
|
109
|
+
RequestError,
|
|
110
|
+
ReturnField,
|
|
111
|
+
Route,
|
|
97
112
|
ScoreBoundary,
|
|
98
113
|
ScoreFilter,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
MinId,
|
|
114
|
+
ServerCredentials,
|
|
115
|
+
SignedEncoding,
|
|
116
|
+
SlotIdRoute,
|
|
117
|
+
SlotKeyRoute,
|
|
118
|
+
SlotType,
|
|
105
119
|
StreamAddOptions,
|
|
106
120
|
StreamClaimOptions,
|
|
107
121
|
StreamGroupOptions,
|
|
@@ -110,78 +124,55 @@ from glide.async_commands.stream import (
|
|
|
110
124
|
StreamReadGroupOptions,
|
|
111
125
|
StreamReadOptions,
|
|
112
126
|
StreamTrimOptions,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
116
|
-
from glide.config import (
|
|
117
|
-
AdvancedGlideClientConfiguration,
|
|
118
|
-
AdvancedGlideClusterClientConfiguration,
|
|
119
|
-
BackoffStrategy,
|
|
120
|
-
GlideClientConfiguration,
|
|
121
|
-
GlideClusterClientConfiguration,
|
|
122
|
-
NodeAddress,
|
|
123
|
-
PeriodicChecksManualInterval,
|
|
124
|
-
PeriodicChecksStatus,
|
|
125
|
-
ProtocolVersion,
|
|
126
|
-
ReadFrom,
|
|
127
|
-
ServerCredentials,
|
|
128
|
-
)
|
|
129
|
-
from glide.constants import (
|
|
130
|
-
OK,
|
|
131
|
-
TOK,
|
|
132
|
-
FtAggregateResponse,
|
|
133
|
-
FtInfoResponse,
|
|
134
|
-
FtProfileResponse,
|
|
135
|
-
FtSearchResponse,
|
|
127
|
+
TagField,
|
|
128
|
+
TBatch,
|
|
136
129
|
TClusterResponse,
|
|
137
130
|
TEncodable,
|
|
131
|
+
TextField,
|
|
138
132
|
TFunctionListResponse,
|
|
139
133
|
TFunctionStatsFullResponse,
|
|
140
134
|
TFunctionStatsSingleNodeResponse,
|
|
135
|
+
TimeoutError,
|
|
141
136
|
TJsonResponse,
|
|
142
137
|
TJsonUniversalResponse,
|
|
138
|
+
TlsAdvancedConfiguration,
|
|
139
|
+
Transaction,
|
|
143
140
|
TResult,
|
|
141
|
+
TrimByMaxLen,
|
|
142
|
+
TrimByMinId,
|
|
144
143
|
TSingleNodeRoute,
|
|
145
144
|
TXInfoStreamFullResponse,
|
|
146
145
|
TXInfoStreamResponse,
|
|
146
|
+
UnsignedEncoding,
|
|
147
|
+
UpdateOptions,
|
|
148
|
+
VectorAlgorithm,
|
|
149
|
+
VectorField,
|
|
150
|
+
VectorFieldAttributes,
|
|
151
|
+
VectorFieldAttributesFlat,
|
|
152
|
+
VectorFieldAttributesHnsw,
|
|
153
|
+
VectorType,
|
|
154
|
+
json_batch,
|
|
147
155
|
)
|
|
148
|
-
from glide.exceptions import (
|
|
149
|
-
ClosingError,
|
|
150
|
-
ConfigurationError,
|
|
151
|
-
ConnectionError,
|
|
152
|
-
ExecAbortError,
|
|
153
|
-
GlideError,
|
|
154
|
-
RequestError,
|
|
155
|
-
TimeoutError,
|
|
156
|
-
)
|
|
157
|
-
from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient
|
|
158
|
-
from glide.logger import Level as LogLevel
|
|
159
|
-
from glide.logger import Logger
|
|
160
|
-
from glide.routes import (
|
|
161
|
-
AllNodes,
|
|
162
|
-
AllPrimaries,
|
|
163
|
-
ByAddressRoute,
|
|
164
|
-
RandomNode,
|
|
165
|
-
Route,
|
|
166
|
-
SlotIdRoute,
|
|
167
|
-
SlotKeyRoute,
|
|
168
|
-
SlotType,
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
from .glide import ClusterScanCursor, Script
|
|
172
156
|
|
|
173
|
-
|
|
157
|
+
from .async_commands import ft, glide_json
|
|
158
|
+
from .glide_client import GlideClient, GlideClusterClient, TGlideClient
|
|
159
|
+
from .logger import Level as LogLevel
|
|
160
|
+
from .logger import Logger
|
|
174
161
|
|
|
175
162
|
__all__ = [
|
|
176
163
|
# Client
|
|
164
|
+
"TGlideClient",
|
|
177
165
|
"GlideClient",
|
|
178
166
|
"GlideClusterClient",
|
|
179
167
|
"Batch",
|
|
180
168
|
"ClusterBatch",
|
|
181
169
|
"ClusterTransaction",
|
|
182
170
|
"Transaction",
|
|
183
|
-
"TGlideClient",
|
|
184
171
|
"TBatch",
|
|
172
|
+
# Batch Options
|
|
173
|
+
"BatchOptions",
|
|
174
|
+
"BatchRetryStrategy",
|
|
175
|
+
"ClusterBatchOptions",
|
|
185
176
|
# Config
|
|
186
177
|
"AdvancedGlideClientConfiguration",
|
|
187
178
|
"AdvancedGlideClusterClientConfiguration",
|
|
@@ -191,9 +182,13 @@ __all__ = [
|
|
|
191
182
|
"ReadFrom",
|
|
192
183
|
"ServerCredentials",
|
|
193
184
|
"NodeAddress",
|
|
185
|
+
"OpenTelemetryConfig",
|
|
186
|
+
"OpenTelemetryMetricsConfig",
|
|
187
|
+
"OpenTelemetryTracesConfig",
|
|
194
188
|
"ProtocolVersion",
|
|
195
189
|
"PeriodicChecksManualInterval",
|
|
196
190
|
"PeriodicChecksStatus",
|
|
191
|
+
"TlsAdvancedConfiguration",
|
|
197
192
|
# Response
|
|
198
193
|
"OK",
|
|
199
194
|
"TClusterResponse",
|
|
@@ -243,11 +238,11 @@ __all__ = [
|
|
|
243
238
|
"GeoSearchCount",
|
|
244
239
|
"GeoUnit",
|
|
245
240
|
"GeospatialData",
|
|
241
|
+
"HashFieldConditionalChange",
|
|
246
242
|
"AggregationType",
|
|
247
243
|
"InfBound",
|
|
248
244
|
"InfoSection",
|
|
249
245
|
"InsertPosition",
|
|
250
|
-
"ft",
|
|
251
246
|
"LexBoundary",
|
|
252
247
|
"Limit",
|
|
253
248
|
"ListDirection",
|
|
@@ -303,6 +298,7 @@ __all__ = [
|
|
|
303
298
|
"RequestError",
|
|
304
299
|
"TimeoutError",
|
|
305
300
|
# Ft
|
|
301
|
+
"ft",
|
|
306
302
|
"DataType",
|
|
307
303
|
"DistanceMetricType",
|
|
308
304
|
"Field",
|
|
@@ -4,27 +4,28 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import Dict, List, Mapping, Optional, Union, cast
|
|
6
6
|
|
|
7
|
-
from glide.
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
|
|
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 (
|
|
11
12
|
FlushMode,
|
|
12
13
|
FunctionRestorePolicy,
|
|
13
14
|
InfoSection,
|
|
14
15
|
)
|
|
15
|
-
from
|
|
16
|
+
from glide_shared.constants import (
|
|
16
17
|
TOK,
|
|
17
18
|
TClusterResponse,
|
|
18
19
|
TEncodable,
|
|
19
20
|
TFunctionListResponse,
|
|
20
21
|
TFunctionStatsSingleNodeResponse,
|
|
21
22
|
TResult,
|
|
22
|
-
TSingleNodeRoute,
|
|
23
23
|
)
|
|
24
|
-
from
|
|
25
|
-
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
|
|
26
27
|
|
|
27
|
-
from
|
|
28
|
+
from .core import CoreCommands
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
class ClusterCommands(CoreCommands):
|
|
@@ -74,8 +75,8 @@ class ClusterCommands(CoreCommands):
|
|
|
74
75
|
Args:
|
|
75
76
|
sections (Optional[List[InfoSection]]): A list of InfoSection values specifying which sections of
|
|
76
77
|
information to retrieve. When no parameter is provided, the default option is assumed.
|
|
77
|
-
route (Optional[Route]): The command will be routed to all primaries, unless `route` is provided, in
|
|
78
|
-
case the client will route the command to the nodes defined by `route`. Defaults to None.
|
|
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.
|
|
79
80
|
|
|
80
81
|
Returns:
|
|
81
82
|
TClusterResponse[bytes]: If a single node route is requested, returns a bytes string containing the information for
|
|
@@ -94,128 +95,109 @@ class ClusterCommands(CoreCommands):
|
|
|
94
95
|
self,
|
|
95
96
|
batch: ClusterBatch,
|
|
96
97
|
raise_on_error: bool,
|
|
97
|
-
|
|
98
|
-
timeout: Optional[int] = None,
|
|
99
|
-
retry_server_error: bool = False,
|
|
100
|
-
retry_connection_error: bool = False,
|
|
98
|
+
options: Optional[ClusterBatchOptions] = None,
|
|
101
99
|
) -> Optional[List[TResult]]:
|
|
102
100
|
"""
|
|
103
101
|
Executes a batch by processing the queued commands.
|
|
104
102
|
|
|
105
|
-
|
|
106
|
-
See [Valkey Pipelines (Non-Atomic Batches)](https://valkey.io/docs/topics/pipelining/) for details.
|
|
107
|
-
|
|
108
|
-
#### Routing Behavior:
|
|
109
|
-
|
|
110
|
-
- If a `route` is specified:
|
|
111
|
-
- The entire batch is sent to the specified node.
|
|
103
|
+
**Routing Behavior:**
|
|
112
104
|
|
|
105
|
+
- If a `route` is specified in `ClusterBatchOptions`, the entire batch is sent
|
|
106
|
+
to the specified node.
|
|
113
107
|
- If no `route` is specified:
|
|
114
|
-
- Atomic batches (Transactions)
|
|
115
|
-
If no key is found, the request is sent to a random node.
|
|
116
|
-
- Non-atomic batches (Pipelines)
|
|
117
|
-
key's slot. If no key is present, routing follows the
|
|
118
|
-
Multi-node commands are automatically split and
|
|
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.
|
|
119
114
|
|
|
120
|
-
|
|
115
|
+
**Behavior notes:**
|
|
121
116
|
|
|
122
|
-
- Atomic Batches (Transactions)
|
|
123
|
-
If keys span different slots, the transaction will fail. If the
|
|
124
|
-
`WATCH` command, `
|
|
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`.
|
|
125
120
|
|
|
126
|
-
|
|
121
|
+
**Retry and Redirection:**
|
|
127
122
|
|
|
128
123
|
- If a redirection error occurs:
|
|
129
|
-
- Atomic batches (Transactions)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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`.
|
|
134
129
|
|
|
135
130
|
Args:
|
|
136
|
-
batch (ClusterBatch): A `ClusterBatch`
|
|
137
|
-
raise_on_error (bool): Determines how errors are handled within the batch response.
|
|
138
|
-
`True`, the first encountered error in the batch will be raised as
|
|
139
|
-
exception after all retries and reconnections have been
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
If a redirection error occurs:
|
|
147
|
-
- For Atomic Batches (Transactions), the entire transaction will be redirected.
|
|
148
|
-
- For Non-Atomic Batches (Pipelines), only the commands that encountered redirection errors
|
|
149
|
-
will be redirected.
|
|
150
|
-
timeout (Optional[int]): The duration in milliseconds that the client should wait for the batch request
|
|
151
|
-
to complete. This duration encompasses sending the request, awaiting a response from the server,
|
|
152
|
-
and any required reconnections or retries.
|
|
153
|
-
|
|
154
|
-
If the specified timeout is exceeded, a timeout error will be raised. If not explicitly set,
|
|
155
|
-
the client's default request timeout will be used.
|
|
156
|
-
retry_server_error (bool): If `True`, retriable server errors (e.g., `TRYAGAIN`) will trigger a retry.
|
|
157
|
-
Warning: Retrying server errors may cause commands targeting the same slot to execute out of order.
|
|
158
|
-
Note: Currently supported only for non-atomic batches. Recommended to increase timeout when enabled.
|
|
159
|
-
retry_connection_error (bool): If `True`, connection failures will trigger a retry. Warning:
|
|
160
|
-
Retrying connection errors may lead to duplicate executions, as it is unclear which commands have
|
|
161
|
-
already been processed. Note: Currently supported only for non-atomic batches. Recommended to increase
|
|
162
|
-
timeout when enabled.
|
|
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.
|
|
163
140
|
|
|
164
141
|
Returns:
|
|
165
|
-
Optional[List[TResult]]:
|
|
166
|
-
|
|
167
|
-
the list entry will be `None`. If the batch failed due to a `WATCH` command, `exec` will return
|
|
168
|
-
`None`.
|
|
142
|
+
Optional[List[TResult]]: An array of results, where each entry
|
|
143
|
+
corresponds to a command's execution result.
|
|
169
144
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
>>> atomic_batch.set("key", "1")
|
|
174
|
-
>>> atomic_batch.incr("key")
|
|
175
|
-
>>> atomic_batch.get("key")
|
|
176
|
-
>>> atomic_result = await cluster_client.exec(atomic_batch, false)
|
|
177
|
-
>>> print(f"Atomic Batch Result: {atomic_result}")
|
|
178
|
-
# Expected Output: Atomic Batch Result: [OK, 2, 2]
|
|
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/)
|
|
179
148
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
>>>
|
|
183
|
-
>>> non_atomic_batch.set("key2", "value2")
|
|
184
|
-
>>> non_atomic_batch.get("key1")
|
|
185
|
-
>>> non_atomic_batch.get("key2")
|
|
186
|
-
>>> non_atomic_result = await cluster_client.exec(non_atomic_batch, false)
|
|
187
|
-
>>> print(f"Non-Atomic Batch Result: {non_atomic_result}")
|
|
188
|
-
# Expected Output: Non-Atomic Batch Result: [OK, OK, value1, value2]
|
|
189
|
-
|
|
190
|
-
# Example 3: Atomic batch with options
|
|
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
|
|
191
152
|
>>> atomic_batch = ClusterBatch(is_atomic=True)
|
|
192
153
|
>>> atomic_batch.set("key", "1")
|
|
193
154
|
>>> atomic_batch.incr("key")
|
|
194
155
|
>>> atomic_batch.get("key")
|
|
195
|
-
>>> atomic_result = await cluster_client.exec(
|
|
196
|
-
... atomic_batch,
|
|
197
|
-
... timeout=1000, # Set a timeout of 1000 milliseconds
|
|
198
|
-
... raise_on_error=False # Do not raise an error on failure
|
|
199
|
-
... )
|
|
156
|
+
>>> atomic_result = await cluster_client.exec(atomic_batch, False, options)
|
|
200
157
|
>>> print(f"Atomic Batch Result: {atomic_result}")
|
|
201
158
|
# Output: Atomic Batch Result: [OK, 2, 2]
|
|
202
159
|
|
|
203
|
-
#
|
|
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)
|
|
204
163
|
>>> non_atomic_batch = ClusterBatch(is_atomic=False)
|
|
205
164
|
>>> non_atomic_batch.set("key1", "value1")
|
|
206
165
|
>>> non_atomic_batch.set("key2", "value2")
|
|
207
166
|
>>> non_atomic_batch.get("key1")
|
|
208
167
|
>>> non_atomic_batch.get("key2")
|
|
209
|
-
>>> non_atomic_result = await cluster_client.exec(
|
|
210
|
-
... non_atomic_batch,
|
|
211
|
-
... raise_on_error=False,
|
|
212
|
-
... retry_server_error=True,
|
|
213
|
-
... retry_connection_error=False
|
|
214
|
-
... )
|
|
168
|
+
>>> non_atomic_result = await cluster_client.exec(non_atomic_batch, False, pipeline_options)
|
|
215
169
|
>>> print(f"Non-Atomic Batch Result: {non_atomic_result}")
|
|
216
170
|
# Output: Non-Atomic Batch Result: [OK, OK, value1, value2]
|
|
217
171
|
"""
|
|
218
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
|
+
|
|
219
201
|
return await self._execute_batch(
|
|
220
202
|
commands,
|
|
221
203
|
batch.is_atomic,
|
|
@@ -1439,7 +1421,7 @@ class ClusterCommands(CoreCommands):
|
|
|
1439
1421
|
|
|
1440
1422
|
Examples:
|
|
1441
1423
|
>>> lua_script = Script("return { KEYS[1], ARGV[1] }")
|
|
1442
|
-
>>> await client.invoke_script(lua_script, keys=["foo"], args=["bar"]
|
|
1424
|
+
>>> await client.invoke_script(lua_script, keys=["foo"], args=["bar"])
|
|
1443
1425
|
[b"foo", b"bar"]
|
|
1444
1426
|
"""
|
|
1445
1427
|
return await self._execute_script(script.get_hash(), keys, args)
|