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
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from glide_shared.constants import TSingleNodeRoute
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BatchRetryStrategy:
|
|
9
|
+
"""
|
|
10
|
+
Defines a retry strategy for cluster batch requests, allowing control over retries in case of
|
|
11
|
+
server or connection errors.
|
|
12
|
+
|
|
13
|
+
This strategy determines whether failed commands should be retried, impacting execution order
|
|
14
|
+
and potential side effects.
|
|
15
|
+
|
|
16
|
+
Behavior:
|
|
17
|
+
- If `retry_server_error` is `True`, failed commands with a retriable error (e.g.,
|
|
18
|
+
`TRYAGAIN`) will be retried.
|
|
19
|
+
- If `retry_connection_error` is `True`, batch requests will be retried on
|
|
20
|
+
connection failures.
|
|
21
|
+
|
|
22
|
+
Cautions:
|
|
23
|
+
- **Server Errors:** Retrying may cause commands targeting the same slot to be executed
|
|
24
|
+
out of order.
|
|
25
|
+
- **Connection Errors:** Retrying may lead to duplicate executions, since the server might
|
|
26
|
+
have already received and processed the request before the error occurred.
|
|
27
|
+
|
|
28
|
+
Example Scenario:
|
|
29
|
+
```
|
|
30
|
+
MGET key {key}:1
|
|
31
|
+
SET key "value"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Expected response when keys are empty:
|
|
35
|
+
```
|
|
36
|
+
[None, None]
|
|
37
|
+
"OK"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
However, if the slot is migrating, both commands may return an `ASK` error and be
|
|
41
|
+
redirected. Upon `ASK` redirection, a multi-key command may return a `TRYAGAIN`
|
|
42
|
+
error (triggering a retry), while the `SET` command succeeds immediately. This
|
|
43
|
+
can result in an unintended reordering of commands if the first command is retried
|
|
44
|
+
after the slot stabilizes:
|
|
45
|
+
```
|
|
46
|
+
["value", None]
|
|
47
|
+
"OK"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Note:
|
|
51
|
+
Currently, retry strategies are supported only for non-atomic batches.
|
|
52
|
+
|
|
53
|
+
Default:
|
|
54
|
+
Both `retry_server_error` and `retry_connection_error` are set to `False`.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
retry_server_error (bool): If `True`, failed commands with a retriable error (e.g., `TRYAGAIN`)
|
|
58
|
+
will be automatically retried.
|
|
59
|
+
|
|
60
|
+
⚠️ **Warning:** Enabling this flag may cause commands targeting the same slot to execute
|
|
61
|
+
out of order.
|
|
62
|
+
|
|
63
|
+
By default, this is set to `False`.
|
|
64
|
+
|
|
65
|
+
retry_connection_error (bool): If `True`, batch requests will be retried in case of connection errors.
|
|
66
|
+
|
|
67
|
+
⚠️ **Warning:** Retrying after a connection error may lead to duplicate executions, since
|
|
68
|
+
the server might have already received and processed the request before the error occurred.
|
|
69
|
+
|
|
70
|
+
By default, this is set to `False`.
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
def __init__(
|
|
75
|
+
self,
|
|
76
|
+
retry_server_error: bool = False,
|
|
77
|
+
retry_connection_error: bool = False,
|
|
78
|
+
):
|
|
79
|
+
"""
|
|
80
|
+
Initialize a BatchRetryStrategy.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
retry_server_error (bool): If `True`, failed commands with a retriable error (e.g., `TRYAGAIN`)
|
|
84
|
+
will be automatically retried.
|
|
85
|
+
|
|
86
|
+
⚠️ **Warning:** Enabling this flag may cause commands targeting the same slot to execute
|
|
87
|
+
out of order.
|
|
88
|
+
|
|
89
|
+
By default, this is set to `False`.
|
|
90
|
+
|
|
91
|
+
retry_connection_error (bool): If `True`, batch requests will be retried in case of connection errors.
|
|
92
|
+
|
|
93
|
+
⚠️ **Warning:** Retrying after a connection error may lead to duplicate executions, since
|
|
94
|
+
the server might have already received and processed the request before the error occurred.
|
|
95
|
+
|
|
96
|
+
By default, this is set to `False`.
|
|
97
|
+
|
|
98
|
+
"""
|
|
99
|
+
self.retry_server_error = retry_server_error
|
|
100
|
+
self.retry_connection_error = retry_connection_error
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class BaseBatchOptions:
|
|
104
|
+
"""
|
|
105
|
+
Base options settings class for sending a batch request. Shared settings for standalone and
|
|
106
|
+
cluster batch requests.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
timeout (Optional[int]): The duration in milliseconds that the client should wait for the batch request
|
|
110
|
+
to complete. This duration encompasses sending the request, awaiting a response from the server,
|
|
111
|
+
and any required reconnections or retries. If the specified timeout is exceeded for a pending request,
|
|
112
|
+
it will result in a timeout error. If not explicitly set, the client's default request timeout will be used.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def __init__(
|
|
116
|
+
self,
|
|
117
|
+
timeout: Optional[int] = None,
|
|
118
|
+
):
|
|
119
|
+
"""
|
|
120
|
+
Initialize BaseBatchOptions.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
timeout (Optional[int]): The duration in milliseconds that the client should wait for the batch request
|
|
124
|
+
to complete. This duration encompasses sending the request, awaiting a response from the server,
|
|
125
|
+
and any required reconnections or retries. If the specified timeout is exceeded for a pending request,
|
|
126
|
+
it will result in a timeout error. If not explicitly set, the client's default request timeout will be used.
|
|
127
|
+
"""
|
|
128
|
+
self.timeout = timeout
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class BatchOptions(BaseBatchOptions):
|
|
132
|
+
"""
|
|
133
|
+
Options for a batch request for a standalone client.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
timeout (Optional[int]): The duration in milliseconds that the client should wait for the batch request
|
|
137
|
+
to complete. This duration encompasses sending the request, awaiting a response from the server,
|
|
138
|
+
and any required reconnections or retries. If the specified timeout is exceeded for a pending request,
|
|
139
|
+
it will result in a timeout error. If not explicitly set, the client's default request timeout will be used.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
def __init__(
|
|
143
|
+
self,
|
|
144
|
+
timeout: Optional[int] = None,
|
|
145
|
+
):
|
|
146
|
+
"""
|
|
147
|
+
Options for a batch request for a standalone client
|
|
148
|
+
|
|
149
|
+
Args:
|
|
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. If the specified timeout is exceeded for a pending request,
|
|
153
|
+
it will result in a timeout error. If not explicitly set, the client's default request timeout will be used.
|
|
154
|
+
"""
|
|
155
|
+
super().__init__(timeout)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class ClusterBatchOptions(BaseBatchOptions):
|
|
159
|
+
"""
|
|
160
|
+
Options for cluster batch operations.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
timeout (Optional[int]): The duration in milliseconds that the client should wait for the batch request
|
|
164
|
+
to complete. This duration encompasses sending the request, awaiting a response from the server,
|
|
165
|
+
and any required reconnections or retries. If the specified timeout is exceeded for a pending request,
|
|
166
|
+
it will result in a timeout error. If not explicitly set, the client's default request timeout will be used.
|
|
167
|
+
|
|
168
|
+
route (Optional[TSingleNodeRoute]): Configures single-node routing for the batch request. The client
|
|
169
|
+
will send the batch to the specified node defined by `route`.
|
|
170
|
+
|
|
171
|
+
If a redirection error occurs:
|
|
172
|
+
|
|
173
|
+
- For Atomic Batches (Transactions), the entire transaction will be redirected.
|
|
174
|
+
- For Non-Atomic Batches (Pipelines), only the commands that encountered redirection errors
|
|
175
|
+
will be redirected.
|
|
176
|
+
|
|
177
|
+
retry_strategy (Optional[BatchRetryStrategy]): ⚠️ **Please see `BatchRetryStrategy` and read carefully before enabling these
|
|
178
|
+
options.**
|
|
179
|
+
|
|
180
|
+
Defines the retry strategy for handling cluster batch request failures.
|
|
181
|
+
|
|
182
|
+
This strategy determines whether failed commands should be retried, potentially impacting
|
|
183
|
+
execution order.
|
|
184
|
+
|
|
185
|
+
- If `retry_server_error` is `True`, retriable errors (e.g., TRYAGAIN) will
|
|
186
|
+
trigger a retry.
|
|
187
|
+
- If `retry_connection_error` is `True`, connection failures will trigger a
|
|
188
|
+
retry.
|
|
189
|
+
|
|
190
|
+
**Warnings:**
|
|
191
|
+
|
|
192
|
+
- Retrying server errors may cause commands targeting the same slot to execute out of
|
|
193
|
+
order.
|
|
194
|
+
- Retrying connection errors may lead to duplicate executions, as it is unclear which
|
|
195
|
+
commands have already been processed.
|
|
196
|
+
|
|
197
|
+
**Note:** Currently, retry strategies are supported only for non-atomic batches.
|
|
198
|
+
|
|
199
|
+
**Recommendation:** It is recommended to increase the timeout in `timeout`
|
|
200
|
+
when enabling these strategies.
|
|
201
|
+
|
|
202
|
+
**Default:** Both `retry_server_error` and `retry_connection_error` are set to
|
|
203
|
+
`False`.
|
|
204
|
+
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
def __init__(
|
|
208
|
+
self,
|
|
209
|
+
timeout: Optional[int] = None,
|
|
210
|
+
route: Optional[TSingleNodeRoute] = None,
|
|
211
|
+
retry_strategy: Optional[BatchRetryStrategy] = None,
|
|
212
|
+
):
|
|
213
|
+
"""
|
|
214
|
+
Initialize ClusterBatchOptions.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
timeout (Optional[int]): The duration in milliseconds that the client should wait for the batch request
|
|
218
|
+
to complete. This duration encompasses sending the request, awaiting a response from the server,
|
|
219
|
+
and any required reconnections or retries. If the specified timeout is exceeded for a pending request,
|
|
220
|
+
it will result in a timeout error. If not explicitly set, the client's default request timeout will be used.
|
|
221
|
+
|
|
222
|
+
route (Optional[TSingleNodeRoute]): Configures single-node routing for the batch request. The client
|
|
223
|
+
will send the batch to the specified node defined by `route`.
|
|
224
|
+
|
|
225
|
+
If a redirection error occurs:
|
|
226
|
+
|
|
227
|
+
- For Atomic Batches (Transactions), the entire transaction will be redirected.
|
|
228
|
+
- For Non-Atomic Batches (Pipelines), only the commands that encountered redirection errors
|
|
229
|
+
will be redirected.
|
|
230
|
+
|
|
231
|
+
retry_strategy (Optional[BatchRetryStrategy]): ⚠️ **Please see `BatchRetryStrategy` and read carefully before enabling these
|
|
232
|
+
options.**
|
|
233
|
+
|
|
234
|
+
Defines the retry strategy for handling cluster batch request failures.
|
|
235
|
+
|
|
236
|
+
This strategy determines whether failed commands should be retried, potentially impacting
|
|
237
|
+
execution order.
|
|
238
|
+
|
|
239
|
+
- If `retry_server_error` is `True`, retriable errors (e.g., TRYAGAIN) will
|
|
240
|
+
trigger a retry.
|
|
241
|
+
- If `retry_connection_error` is `True`, connection failures will trigger a
|
|
242
|
+
retry.
|
|
243
|
+
|
|
244
|
+
**Warnings:**
|
|
245
|
+
|
|
246
|
+
- Retrying server errors may cause commands targeting the same slot to execute out of
|
|
247
|
+
order.
|
|
248
|
+
- Retrying connection errors may lead to duplicate executions, as it is unclear which
|
|
249
|
+
commands have already been processed.
|
|
250
|
+
|
|
251
|
+
**Note:** Currently, retry strategies are supported only for non-atomic batches.
|
|
252
|
+
|
|
253
|
+
**Recommendation:** It is recommended to increase the timeout in `timeout`
|
|
254
|
+
when enabling these strategies.
|
|
255
|
+
|
|
256
|
+
**Default:** Both `retry_server_error` and `retry_connection_error` are set to
|
|
257
|
+
`False`.
|
|
258
|
+
"""
|
|
259
|
+
super().__init__(timeout)
|
|
260
|
+
self.retry_strategy = retry_strategy
|
|
261
|
+
self.route = route
|
|
@@ -23,25 +23,27 @@ class BitmapIndexType(Enum):
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class OffsetOptions:
|
|
26
|
+
"""
|
|
27
|
+
Represents offsets specifying a string interval to analyze in the `BITCOUNT` command. The offsets are
|
|
28
|
+
zero-based indexes, with `0` being the first index of the string, `1` being the next index and so on.
|
|
29
|
+
The offsets can also be negative numbers indicating offsets starting at the end of the string, with `-1` being
|
|
30
|
+
the last index of the string, `-2` being the penultimate, and so on.
|
|
31
|
+
|
|
32
|
+
Attributes:
|
|
33
|
+
start (int): The starting offset index.
|
|
34
|
+
end (Optional[int]): The ending offset index. Optional since Valkey version 8.0.0 and above for the BITCOUNT
|
|
35
|
+
command. If not provided, it will default to the end of the string.
|
|
36
|
+
index_type (Optional[BitmapIndexType]): The index offset type. This option can only be specified if you are
|
|
37
|
+
using Valkey version 7.0.0 or above. Could be either `BitmapIndexType.BYTE` or `BitmapIndexType.BIT`.
|
|
38
|
+
If no index type is provided, the indexes will be assumed to be byte indexes.
|
|
39
|
+
"""
|
|
40
|
+
|
|
26
41
|
def __init__(
|
|
27
42
|
self,
|
|
28
43
|
start: int,
|
|
29
44
|
end: Optional[int] = None,
|
|
30
45
|
index_type: Optional[BitmapIndexType] = None,
|
|
31
46
|
):
|
|
32
|
-
"""
|
|
33
|
-
Represents offsets specifying a string interval to analyze in the `BITCOUNT` command. The offsets are
|
|
34
|
-
zero-based indexes, with `0` being the first index of the string, `1` being the next index and so on.
|
|
35
|
-
The offsets can also be negative numbers indicating offsets starting at the end of the string, with `-1` being
|
|
36
|
-
the last index of the string, `-2` being the penultimate, and so on.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
start (int): The starting offset index.
|
|
40
|
-
end (int): The ending offset index. Optional since Valkey version 8.0.0 and above. If not provided, it will default to the end of the string.
|
|
41
|
-
index_type (Optional[BitmapIndexType]): The index offset type. This option can only be specified if you are
|
|
42
|
-
using Valkey version 7.0.0 or above. Could be either `BitmapIndexType.BYTE` or `BitmapIndexType.BIT`.
|
|
43
|
-
If no index type is provided, the indexes will be assumed to be byte indexes.
|
|
44
|
-
"""
|
|
45
47
|
self.start = start
|
|
46
48
|
self.end = end
|
|
47
49
|
self.index_type = index_type
|
|
@@ -84,16 +86,17 @@ class BitEncoding(ABC):
|
|
|
84
86
|
|
|
85
87
|
|
|
86
88
|
class SignedEncoding(BitEncoding):
|
|
87
|
-
|
|
89
|
+
"""
|
|
90
|
+
Represents a signed argument encoding. Must be less than 65 bits long.
|
|
91
|
+
|
|
92
|
+
Attributes:
|
|
93
|
+
encoding_length (int): The bit size of the encoding.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
#: Prefix specifying that the encoding is signed.
|
|
88
97
|
SIGNED_ENCODING_PREFIX = "i"
|
|
89
98
|
|
|
90
99
|
def __init__(self, encoding_length: int):
|
|
91
|
-
"""
|
|
92
|
-
Represents a signed argument encoding. Must be less than 65 bits long.
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
encoding_length (int): The bit size of the encoding.
|
|
96
|
-
"""
|
|
97
100
|
self._encoding = f"{self.SIGNED_ENCODING_PREFIX}{str(encoding_length)}"
|
|
98
101
|
|
|
99
102
|
def to_arg(self) -> str:
|
|
@@ -101,16 +104,17 @@ class SignedEncoding(BitEncoding):
|
|
|
101
104
|
|
|
102
105
|
|
|
103
106
|
class UnsignedEncoding(BitEncoding):
|
|
104
|
-
|
|
107
|
+
"""
|
|
108
|
+
Represents an unsigned argument encoding. Must be less than 64 bits long.
|
|
109
|
+
|
|
110
|
+
Attributes:
|
|
111
|
+
encoding_length (int): The bit size of the encoding.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
#: Prefix specifying that the encoding is unsigned.
|
|
105
115
|
UNSIGNED_ENCODING_PREFIX = "u"
|
|
106
116
|
|
|
107
117
|
def __init__(self, encoding_length: int):
|
|
108
|
-
"""
|
|
109
|
-
Represents an unsigned argument encoding. Must be less than 64 bits long.
|
|
110
|
-
|
|
111
|
-
Args:
|
|
112
|
-
encoding_length (int): The bit size of the encoding.
|
|
113
|
-
"""
|
|
114
118
|
self._encoding = f"{self.UNSIGNED_ENCODING_PREFIX}{str(encoding_length)}"
|
|
115
119
|
|
|
116
120
|
def to_arg(self) -> str:
|
|
@@ -130,17 +134,18 @@ class BitFieldOffset(ABC):
|
|
|
130
134
|
|
|
131
135
|
|
|
132
136
|
class BitOffset(BitFieldOffset):
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
equal to 0.
|
|
137
|
+
"""
|
|
138
|
+
Represents an offset in an array of bits for the `BITFIELD` or `BITFIELD_RO` commands. Must be greater than or
|
|
139
|
+
equal to 0.
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
For example, if we have the binary `01101001` with offset of 1 for an unsigned encoding of size 4, then the value
|
|
142
|
+
is 13 from `0(1101)001`.
|
|
140
143
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
Attributes:
|
|
145
|
+
offset (int): The bit index offset in the array of bits.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
def __init__(self, offset: int):
|
|
144
149
|
self._offset = str(offset)
|
|
145
150
|
|
|
146
151
|
def to_arg(self) -> str:
|
|
@@ -148,22 +153,23 @@ class BitOffset(BitFieldOffset):
|
|
|
148
153
|
|
|
149
154
|
|
|
150
155
|
class BitOffsetMultiplier(BitFieldOffset):
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
"""
|
|
156
|
-
Represents an offset in an array of bits for the `BITFIELD` or `BITFIELD_RO` commands. The bit offset index is
|
|
157
|
-
calculated as the numerical value of the offset multiplied by the encoding value. Must be greater than or equal
|
|
158
|
-
to 0.
|
|
156
|
+
"""
|
|
157
|
+
Represents an offset in an array of bits for the `BITFIELD` or `BITFIELD_RO` commands. The bit offset index is
|
|
158
|
+
calculated as the numerical value of the offset multiplied by the encoding value. Must be greater than or equal
|
|
159
|
+
to 0.
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
For example, if we have the binary 01101001 with offset multiplier of 1 for an unsigned encoding of size 4, then
|
|
162
|
+
the value is 9 from `0110(1001)`.
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
Attributes:
|
|
165
|
+
offset (int): The offset in the array of bits, which will be multiplied by the encoding value to get the
|
|
165
166
|
final bit index offset.
|
|
166
|
-
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
#: Prefix specifying that the offset uses an encoding multiplier.
|
|
170
|
+
OFFSET_MULTIPLIER_PREFIX = "#"
|
|
171
|
+
|
|
172
|
+
def __init__(self, offset: int):
|
|
167
173
|
self._offset = f"{self.OFFSET_MULTIPLIER_PREFIX}{str(offset)}"
|
|
168
174
|
|
|
169
175
|
def to_arg(self) -> str:
|
|
@@ -182,17 +188,18 @@ class BitFieldSubCommands(ABC):
|
|
|
182
188
|
|
|
183
189
|
|
|
184
190
|
class BitFieldGet(BitFieldSubCommands):
|
|
185
|
-
|
|
191
|
+
"""
|
|
192
|
+
Represents the "GET" subcommand for getting a value in the binary representation of the string stored in `key`.
|
|
193
|
+
|
|
194
|
+
Attributes:
|
|
195
|
+
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
196
|
+
offset (BitFieldOffset): The offset in the array of bits from which to get the value.
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
#: "GET" subcommand string for use in the `BITFIELD` or `BITFIELD_RO` commands.
|
|
186
200
|
GET_COMMAND_STRING = "GET"
|
|
187
201
|
|
|
188
202
|
def __init__(self, encoding: BitEncoding, offset: BitFieldOffset):
|
|
189
|
-
"""
|
|
190
|
-
Represents the "GET" subcommand for getting a value in the binary representation of the string stored in `key`.
|
|
191
|
-
|
|
192
|
-
Args:
|
|
193
|
-
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
194
|
-
offset (BitFieldOffset): The offset in the array of bits from which to get the value.
|
|
195
|
-
"""
|
|
196
203
|
self._encoding = encoding
|
|
197
204
|
self._offset = offset
|
|
198
205
|
|
|
@@ -201,18 +208,19 @@ class BitFieldGet(BitFieldSubCommands):
|
|
|
201
208
|
|
|
202
209
|
|
|
203
210
|
class BitFieldSet(BitFieldSubCommands):
|
|
204
|
-
|
|
211
|
+
"""
|
|
212
|
+
Represents the "SET" subcommand for setting bits in the binary representation of the string stored in `key`.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
216
|
+
offset (BitOffset): The offset in the array of bits where the value will be set.
|
|
217
|
+
value (int): The value to set the bits in the binary value to.
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
#: "SET" subcommand string for use in the `BITFIELD` command.
|
|
205
221
|
SET_COMMAND_STRING = "SET"
|
|
206
222
|
|
|
207
223
|
def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, value: int):
|
|
208
|
-
"""
|
|
209
|
-
Represents the "SET" subcommand for setting bits in the binary representation of the string stored in `key`.
|
|
210
|
-
|
|
211
|
-
Args:
|
|
212
|
-
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
213
|
-
offset (BitOffset): The offset in the array of bits where the value will be set.
|
|
214
|
-
value (int): The value to set the bits in the binary value to.
|
|
215
|
-
"""
|
|
216
224
|
self._encoding = encoding
|
|
217
225
|
self._offset = offset
|
|
218
226
|
self._value = value
|
|
@@ -227,19 +235,20 @@ class BitFieldSet(BitFieldSubCommands):
|
|
|
227
235
|
|
|
228
236
|
|
|
229
237
|
class BitFieldIncrBy(BitFieldSubCommands):
|
|
230
|
-
|
|
238
|
+
"""
|
|
239
|
+
Represents the "INCRBY" subcommand for increasing or decreasing bits in the binary representation of the
|
|
240
|
+
string stored in `key`.
|
|
241
|
+
|
|
242
|
+
Attributes:
|
|
243
|
+
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
244
|
+
offset (BitOffset): The offset in the array of bits where the value will be incremented.
|
|
245
|
+
increment (int): The value to increment the bits in the binary value by.
|
|
246
|
+
"""
|
|
247
|
+
|
|
248
|
+
#: "INCRBY" subcommand string for use in the `BITFIELD` command.
|
|
231
249
|
INCRBY_COMMAND_STRING = "INCRBY"
|
|
232
250
|
|
|
233
251
|
def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, increment: int):
|
|
234
|
-
"""
|
|
235
|
-
Represents the "INCRBY" subcommand for increasing or decreasing bits in the binary representation of the
|
|
236
|
-
string stored in `key`.
|
|
237
|
-
|
|
238
|
-
Args:
|
|
239
|
-
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
240
|
-
offset (BitOffset): The offset in the array of bits where the value will be incremented.
|
|
241
|
-
increment (int): The value to increment the bits in the binary value by.
|
|
242
|
-
"""
|
|
243
252
|
self._encoding = encoding
|
|
244
253
|
self._offset = offset
|
|
245
254
|
self._increment = increment
|
|
@@ -260,8 +269,8 @@ class BitOverflowControl(Enum):
|
|
|
260
269
|
|
|
261
270
|
WRAP = "WRAP"
|
|
262
271
|
"""
|
|
263
|
-
Performs modulo when overflows occur with unsigned encoding. When overflows occur with signed encoding, the value
|
|
264
|
-
restarts at the most negative value. When underflows occur with signed encoding, the value restarts at the most
|
|
272
|
+
Performs modulo when overflows occur with unsigned encoding. When overflows occur with signed encoding, the value
|
|
273
|
+
restarts at the most negative value. When underflows occur with signed encoding, the value restarts at the most
|
|
265
274
|
positive value.
|
|
266
275
|
"""
|
|
267
276
|
SAT = "SAT"
|
|
@@ -275,17 +284,18 @@ class BitOverflowControl(Enum):
|
|
|
275
284
|
|
|
276
285
|
|
|
277
286
|
class BitFieldOverflow(BitFieldSubCommands):
|
|
278
|
-
|
|
287
|
+
"""
|
|
288
|
+
Represents the "OVERFLOW" subcommand that determines the result of the "SET" or "INCRBY" `BITFIELD` subcommands
|
|
289
|
+
when an underflow or overflow occurs.
|
|
290
|
+
|
|
291
|
+
Attributes:
|
|
292
|
+
overflow_control (BitOverflowControl): The desired overflow behavior.
|
|
293
|
+
"""
|
|
294
|
+
|
|
295
|
+
#: "OVERFLOW" subcommand string for use in the `BITFIELD` command.
|
|
279
296
|
OVERFLOW_COMMAND_STRING = "OVERFLOW"
|
|
280
297
|
|
|
281
298
|
def __init__(self, overflow_control: BitOverflowControl):
|
|
282
|
-
"""
|
|
283
|
-
Represents the "OVERFLOW" subcommand that determines the result of the "SET" or "INCRBY" `BITFIELD` subcommands
|
|
284
|
-
when an underflow or overflow occurs.
|
|
285
|
-
|
|
286
|
-
Args:
|
|
287
|
-
overflow_control (BitOverflowControl): The desired overflow behavior.
|
|
288
|
-
"""
|
|
289
299
|
self._overflow_control = overflow_control
|
|
290
300
|
|
|
291
301
|
def to_args(self) -> List[str]:
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import List, Optional, Union
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
class Limit:
|
|
@@ -12,7 +11,7 @@ class Limit:
|
|
|
12
11
|
similar to the `LIMIT` clause in SQL (e.g., `SELECT LIMIT offset, count`).
|
|
13
12
|
|
|
14
13
|
This class can be utilized in multiple commands that support limit options,
|
|
15
|
-
such as [ZRANGE](https://valkey.io/commands/zrange), [SORT](https://valkey.io/commands/sort/)
|
|
14
|
+
such as [ZRANGE](https://valkey.io/commands/zrange), [SORT](https://valkey.io/commands/sort/) and others.
|
|
16
15
|
|
|
17
16
|
Args:
|
|
18
17
|
offset (int): The starting position of the range, zero based.
|
|
@@ -34,9 +33,11 @@ class OrderBy(Enum):
|
|
|
34
33
|
Enumeration representing sorting order options.
|
|
35
34
|
|
|
36
35
|
This enum is used for the following commands:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
|
|
37
|
+
- `SORT`: General sorting in ascending or descending order.
|
|
38
|
+
- `GEOSEARCH`: Sorting items based on their proximity to a center point.
|
|
39
|
+
- `FT.AGGREGATE`: Used in the SortBy clause of the FT.AGGREGATE command.
|
|
40
|
+
|
|
40
41
|
"""
|
|
41
42
|
|
|
42
43
|
ASC = "ASC"
|
|
@@ -93,7 +94,7 @@ class ObjectType(Enum):
|
|
|
93
94
|
|
|
94
95
|
HASH = "Hash"
|
|
95
96
|
"""
|
|
96
|
-
Represents a hash data type.
|
|
97
|
+
Represents a hash data type.
|
|
97
98
|
"""
|
|
98
99
|
|
|
99
100
|
STREAM = "Stream"
|