valkey-glide 1.3.5__cp39-cp39-macosx_11_0_arm64.whl → 2.2.2__cp39-cp39-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- glide/__init__.py +165 -107
- glide/async_commands/cluster_commands.py +318 -136
- glide/async_commands/core.py +1770 -992
- glide/async_commands/{server_modules/ft.py → ft.py} +91 -21
- glide/async_commands/{server_modules/glide_json.py → glide_json.py} +148 -134
- glide/async_commands/standalone_commands.py +203 -137
- glide/glide.cpython-39-darwin.so +0 -0
- glide/glide.pyi +26 -1
- glide/glide_client.py +352 -135
- glide/logger.py +34 -22
- glide/opentelemetry.py +185 -0
- glide_shared/__init__.py +330 -0
- glide_shared/commands/__init__.py +0 -0
- glide/async_commands/transaction.py → glide_shared/commands/batch.py +1839 -1017
- glide_shared/commands/batch_options.py +261 -0
- {glide/async_commands → glide_shared/commands}/bitmap.py +94 -85
- {glide/async_commands → glide_shared/commands}/command_args.py +7 -6
- glide_shared/commands/core_options.py +407 -0
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +18 -11
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +27 -13
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +16 -11
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +16 -8
- {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +160 -130
- glide_shared/commands/server_modules/json_options.py +93 -0
- {glide/async_commands → glide_shared/commands}/sorted_set.py +41 -31
- {glide/async_commands → glide_shared/commands}/stream.py +95 -88
- glide_shared/config.py +975 -0
- {glide → glide_shared}/constants.py +11 -7
- {glide → glide_shared}/exceptions.py +27 -1
- glide_shared/protobuf/command_request_pb2.py +56 -0
- glide_shared/protobuf/connection_request_pb2.py +56 -0
- {glide → glide_shared}/protobuf/response_pb2.py +6 -6
- {glide → glide_shared}/protobuf_codec.py +7 -6
- glide_shared/routes.py +161 -0
- valkey_glide-2.2.2.dist-info/METADATA +211 -0
- valkey_glide-2.2.2.dist-info/RECORD +40 -0
- glide/config.py +0 -590
- glide/protobuf/command_request_pb2.py +0 -54
- glide/protobuf/command_request_pb2.pyi +0 -1164
- glide/protobuf/connection_request_pb2.py +0 -52
- glide/protobuf/connection_request_pb2.pyi +0 -292
- glide/protobuf/response_pb2.pyi +0 -101
- glide/routes.py +0 -114
- valkey_glide-1.3.5.dist-info/METADATA +0 -125
- valkey_glide-1.3.5.dist-info/RECORD +0 -37
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
- {valkey_glide-1.3.5.dist-info → valkey_glide-2.2.2.dist-info}/WHEEL +0 -0
|
@@ -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,26 +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 (Optional[int]): The ending offset index. Optional since Valkey version 8.0.0 and above for the BITCOUNT
|
|
41
|
-
command. If not provided, it will default to the end of the string.
|
|
42
|
-
index_type (Optional[BitmapIndexType]): The index offset type. This option can only be specified if you are
|
|
43
|
-
using Valkey version 7.0.0 or above. Could be either `BitmapIndexType.BYTE` or `BitmapIndexType.BIT`.
|
|
44
|
-
If no index type is provided, the indexes will be assumed to be byte indexes.
|
|
45
|
-
"""
|
|
46
47
|
self.start = start
|
|
47
48
|
self.end = end
|
|
48
49
|
self.index_type = index_type
|
|
@@ -85,16 +86,17 @@ class BitEncoding(ABC):
|
|
|
85
86
|
|
|
86
87
|
|
|
87
88
|
class SignedEncoding(BitEncoding):
|
|
88
|
-
|
|
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.
|
|
89
97
|
SIGNED_ENCODING_PREFIX = "i"
|
|
90
98
|
|
|
91
99
|
def __init__(self, encoding_length: int):
|
|
92
|
-
"""
|
|
93
|
-
Represents a signed argument encoding. Must be less than 65 bits long.
|
|
94
|
-
|
|
95
|
-
Args:
|
|
96
|
-
encoding_length (int): The bit size of the encoding.
|
|
97
|
-
"""
|
|
98
100
|
self._encoding = f"{self.SIGNED_ENCODING_PREFIX}{str(encoding_length)}"
|
|
99
101
|
|
|
100
102
|
def to_arg(self) -> str:
|
|
@@ -102,16 +104,17 @@ class SignedEncoding(BitEncoding):
|
|
|
102
104
|
|
|
103
105
|
|
|
104
106
|
class UnsignedEncoding(BitEncoding):
|
|
105
|
-
|
|
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.
|
|
106
115
|
UNSIGNED_ENCODING_PREFIX = "u"
|
|
107
116
|
|
|
108
117
|
def __init__(self, encoding_length: int):
|
|
109
|
-
"""
|
|
110
|
-
Represents an unsigned argument encoding. Must be less than 64 bits long.
|
|
111
|
-
|
|
112
|
-
Args:
|
|
113
|
-
encoding_length (int): The bit size of the encoding.
|
|
114
|
-
"""
|
|
115
118
|
self._encoding = f"{self.UNSIGNED_ENCODING_PREFIX}{str(encoding_length)}"
|
|
116
119
|
|
|
117
120
|
def to_arg(self) -> str:
|
|
@@ -131,17 +134,18 @@ class BitFieldOffset(ABC):
|
|
|
131
134
|
|
|
132
135
|
|
|
133
136
|
class BitOffset(BitFieldOffset):
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
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.
|
|
138
140
|
|
|
139
|
-
|
|
140
|
-
|
|
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`.
|
|
141
143
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
Attributes:
|
|
145
|
+
offset (int): The bit index offset in the array of bits.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
def __init__(self, offset: int):
|
|
145
149
|
self._offset = str(offset)
|
|
146
150
|
|
|
147
151
|
def to_arg(self) -> str:
|
|
@@ -149,22 +153,23 @@ class BitOffset(BitFieldOffset):
|
|
|
149
153
|
|
|
150
154
|
|
|
151
155
|
class BitOffsetMultiplier(BitFieldOffset):
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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.
|
|
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.
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
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)`.
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
Attributes:
|
|
165
|
+
offset (int): The offset in the array of bits, which will be multiplied by the encoding value to get the
|
|
166
166
|
final bit index offset.
|
|
167
|
-
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
#: Prefix specifying that the offset uses an encoding multiplier.
|
|
170
|
+
OFFSET_MULTIPLIER_PREFIX = "#"
|
|
171
|
+
|
|
172
|
+
def __init__(self, offset: int):
|
|
168
173
|
self._offset = f"{self.OFFSET_MULTIPLIER_PREFIX}{str(offset)}"
|
|
169
174
|
|
|
170
175
|
def to_arg(self) -> str:
|
|
@@ -183,17 +188,18 @@ class BitFieldSubCommands(ABC):
|
|
|
183
188
|
|
|
184
189
|
|
|
185
190
|
class BitFieldGet(BitFieldSubCommands):
|
|
186
|
-
|
|
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.
|
|
187
200
|
GET_COMMAND_STRING = "GET"
|
|
188
201
|
|
|
189
202
|
def __init__(self, encoding: BitEncoding, offset: BitFieldOffset):
|
|
190
|
-
"""
|
|
191
|
-
Represents the "GET" subcommand for getting a value in the binary representation of the string stored in `key`.
|
|
192
|
-
|
|
193
|
-
Args:
|
|
194
|
-
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
195
|
-
offset (BitFieldOffset): The offset in the array of bits from which to get the value.
|
|
196
|
-
"""
|
|
197
203
|
self._encoding = encoding
|
|
198
204
|
self._offset = offset
|
|
199
205
|
|
|
@@ -202,18 +208,19 @@ class BitFieldGet(BitFieldSubCommands):
|
|
|
202
208
|
|
|
203
209
|
|
|
204
210
|
class BitFieldSet(BitFieldSubCommands):
|
|
205
|
-
|
|
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.
|
|
206
221
|
SET_COMMAND_STRING = "SET"
|
|
207
222
|
|
|
208
223
|
def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, value: int):
|
|
209
|
-
"""
|
|
210
|
-
Represents the "SET" subcommand for setting bits in the binary representation of the string stored in `key`.
|
|
211
|
-
|
|
212
|
-
Args:
|
|
213
|
-
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
214
|
-
offset (BitOffset): The offset in the array of bits where the value will be set.
|
|
215
|
-
value (int): The value to set the bits in the binary value to.
|
|
216
|
-
"""
|
|
217
224
|
self._encoding = encoding
|
|
218
225
|
self._offset = offset
|
|
219
226
|
self._value = value
|
|
@@ -228,19 +235,20 @@ class BitFieldSet(BitFieldSubCommands):
|
|
|
228
235
|
|
|
229
236
|
|
|
230
237
|
class BitFieldIncrBy(BitFieldSubCommands):
|
|
231
|
-
|
|
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.
|
|
232
249
|
INCRBY_COMMAND_STRING = "INCRBY"
|
|
233
250
|
|
|
234
251
|
def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, increment: int):
|
|
235
|
-
"""
|
|
236
|
-
Represents the "INCRBY" subcommand for increasing or decreasing bits in the binary representation of the
|
|
237
|
-
string stored in `key`.
|
|
238
|
-
|
|
239
|
-
Args:
|
|
240
|
-
encoding (BitEncoding): The bit encoding for the subcommand.
|
|
241
|
-
offset (BitOffset): The offset in the array of bits where the value will be incremented.
|
|
242
|
-
increment (int): The value to increment the bits in the binary value by.
|
|
243
|
-
"""
|
|
244
252
|
self._encoding = encoding
|
|
245
253
|
self._offset = offset
|
|
246
254
|
self._increment = increment
|
|
@@ -276,17 +284,18 @@ class BitOverflowControl(Enum):
|
|
|
276
284
|
|
|
277
285
|
|
|
278
286
|
class BitFieldOverflow(BitFieldSubCommands):
|
|
279
|
-
|
|
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.
|
|
280
296
|
OVERFLOW_COMMAND_STRING = "OVERFLOW"
|
|
281
297
|
|
|
282
298
|
def __init__(self, overflow_control: BitOverflowControl):
|
|
283
|
-
"""
|
|
284
|
-
Represents the "OVERFLOW" subcommand that determines the result of the "SET" or "INCRBY" `BITFIELD` subcommands
|
|
285
|
-
when an underflow or overflow occurs.
|
|
286
|
-
|
|
287
|
-
Args:
|
|
288
|
-
overflow_control (BitOverflowControl): The desired overflow behavior.
|
|
289
|
-
"""
|
|
290
299
|
self._overflow_control = overflow_control
|
|
291
300
|
|
|
292
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"
|