valkey-glide 2.2.1rc3__cp314-cp314-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.
Files changed (40) hide show
  1. glide/__init__.py +388 -0
  2. glide/async_commands/__init__.py +5 -0
  3. glide/async_commands/cluster_commands.py +1476 -0
  4. glide/async_commands/core.py +7818 -0
  5. glide/async_commands/ft.py +465 -0
  6. glide/async_commands/glide_json.py +1269 -0
  7. glide/async_commands/standalone_commands.py +1001 -0
  8. glide/glide.cpython-314-darwin.so +0 -0
  9. glide/glide.pyi +61 -0
  10. glide/glide_client.py +821 -0
  11. glide/logger.py +97 -0
  12. glide/opentelemetry.py +185 -0
  13. glide/py.typed +0 -0
  14. glide_shared/__init__.py +330 -0
  15. glide_shared/commands/__init__.py +0 -0
  16. glide_shared/commands/batch.py +5997 -0
  17. glide_shared/commands/batch_options.py +261 -0
  18. glide_shared/commands/bitmap.py +320 -0
  19. glide_shared/commands/command_args.py +103 -0
  20. glide_shared/commands/core_options.py +407 -0
  21. glide_shared/commands/server_modules/ft_options/ft_aggregate_options.py +300 -0
  22. glide_shared/commands/server_modules/ft_options/ft_constants.py +84 -0
  23. glide_shared/commands/server_modules/ft_options/ft_create_options.py +423 -0
  24. glide_shared/commands/server_modules/ft_options/ft_profile_options.py +113 -0
  25. glide_shared/commands/server_modules/ft_options/ft_search_options.py +139 -0
  26. glide_shared/commands/server_modules/json_batch.py +820 -0
  27. glide_shared/commands/server_modules/json_options.py +93 -0
  28. glide_shared/commands/sorted_set.py +412 -0
  29. glide_shared/commands/stream.py +449 -0
  30. glide_shared/config.py +975 -0
  31. glide_shared/constants.py +124 -0
  32. glide_shared/exceptions.py +88 -0
  33. glide_shared/protobuf/command_request_pb2.py +56 -0
  34. glide_shared/protobuf/connection_request_pb2.py +56 -0
  35. glide_shared/protobuf/response_pb2.py +32 -0
  36. glide_shared/protobuf_codec.py +110 -0
  37. glide_shared/routes.py +161 -0
  38. valkey_glide-2.2.1rc3.dist-info/METADATA +210 -0
  39. valkey_glide-2.2.1rc3.dist-info/RECORD +40 -0
  40. valkey_glide-2.2.1rc3.dist-info/WHEEL +4 -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
@@ -0,0 +1,320 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+ from abc import ABC, abstractmethod
3
+ from enum import Enum
4
+ from typing import List, Optional
5
+
6
+
7
+ class BitmapIndexType(Enum):
8
+ """
9
+ Enumeration specifying if index arguments are BYTE indexes or BIT indexes. Can be specified in `OffsetOptions`,
10
+ which is an optional argument to the `BITCOUNT` command.
11
+
12
+ Since: Valkey version 7.0.0.
13
+ """
14
+
15
+ BYTE = "BYTE"
16
+ """
17
+ Specifies that indexes provided to `OffsetOptions` are byte indexes.
18
+ """
19
+ BIT = "BIT"
20
+ """
21
+ Specifies that indexes provided to `OffsetOptions` are bit indexes.
22
+ """
23
+
24
+
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
+
41
+ def __init__(
42
+ self,
43
+ start: int,
44
+ end: Optional[int] = None,
45
+ index_type: Optional[BitmapIndexType] = None,
46
+ ):
47
+ self.start = start
48
+ self.end = end
49
+ self.index_type = index_type
50
+
51
+ def to_args(self) -> List[str]:
52
+ args = [str(self.start)]
53
+ if self.end:
54
+ args.append(str(self.end))
55
+ if self.index_type is not None:
56
+ args.append(self.index_type.value)
57
+
58
+ return args
59
+
60
+
61
+ class BitwiseOperation(Enum):
62
+ """
63
+ Enumeration defining the bitwise operation to use in the `BITOP` command. Specifies the bitwise operation to
64
+ perform between the passed in keys.
65
+ """
66
+
67
+ AND = "AND"
68
+ OR = "OR"
69
+ XOR = "XOR"
70
+ NOT = "NOT"
71
+
72
+
73
+ class BitEncoding(ABC):
74
+ """
75
+ Abstract Base Class used to specify a signed or unsigned argument encoding for the `BITFIELD` or `BITFIELD_RO`
76
+ commands.
77
+ """
78
+
79
+ @abstractmethod
80
+ def to_arg(self) -> str:
81
+ """
82
+ Returns the encoding as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
83
+ commands.
84
+ """
85
+ pass
86
+
87
+
88
+ class SignedEncoding(BitEncoding):
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.
97
+ SIGNED_ENCODING_PREFIX = "i"
98
+
99
+ def __init__(self, encoding_length: int):
100
+ self._encoding = f"{self.SIGNED_ENCODING_PREFIX}{str(encoding_length)}"
101
+
102
+ def to_arg(self) -> str:
103
+ return self._encoding
104
+
105
+
106
+ class UnsignedEncoding(BitEncoding):
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.
115
+ UNSIGNED_ENCODING_PREFIX = "u"
116
+
117
+ def __init__(self, encoding_length: int):
118
+ self._encoding = f"{self.UNSIGNED_ENCODING_PREFIX}{str(encoding_length)}"
119
+
120
+ def to_arg(self) -> str:
121
+ return self._encoding
122
+
123
+
124
+ class BitFieldOffset(ABC):
125
+ """Abstract Base Class representing an offset for an array of bits for the `BITFIELD` or `BITFIELD_RO` commands."""
126
+
127
+ @abstractmethod
128
+ def to_arg(self) -> str:
129
+ """
130
+ Returns the offset as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
131
+ commands.
132
+ """
133
+ pass
134
+
135
+
136
+ class BitOffset(BitFieldOffset):
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.
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`.
143
+
144
+ Attributes:
145
+ offset (int): The bit index offset in the array of bits.
146
+ """
147
+
148
+ def __init__(self, offset: int):
149
+ self._offset = str(offset)
150
+
151
+ def to_arg(self) -> str:
152
+ return self._offset
153
+
154
+
155
+ class BitOffsetMultiplier(BitFieldOffset):
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
+
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
+
164
+ Attributes:
165
+ offset (int): The offset in the array of bits, which will be multiplied by the encoding value to get the
166
+ final bit index offset.
167
+ """
168
+
169
+ #: Prefix specifying that the offset uses an encoding multiplier.
170
+ OFFSET_MULTIPLIER_PREFIX = "#"
171
+
172
+ def __init__(self, offset: int):
173
+ self._offset = f"{self.OFFSET_MULTIPLIER_PREFIX}{str(offset)}"
174
+
175
+ def to_arg(self) -> str:
176
+ return self._offset
177
+
178
+
179
+ class BitFieldSubCommands(ABC):
180
+ """Abstract Base Class representing subcommands for the `BITFIELD` or `BITFIELD_RO` commands."""
181
+
182
+ @abstractmethod
183
+ def to_args(self) -> List[str]:
184
+ """
185
+ Returns the subcommand as a list of string arguments to be used in the `BITFIELD` or `BITFIELD_RO` commands.
186
+ """
187
+ pass
188
+
189
+
190
+ class BitFieldGet(BitFieldSubCommands):
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.
200
+ GET_COMMAND_STRING = "GET"
201
+
202
+ def __init__(self, encoding: BitEncoding, offset: BitFieldOffset):
203
+ self._encoding = encoding
204
+ self._offset = offset
205
+
206
+ def to_args(self) -> List[str]:
207
+ return [self.GET_COMMAND_STRING, self._encoding.to_arg(), self._offset.to_arg()]
208
+
209
+
210
+ class BitFieldSet(BitFieldSubCommands):
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.
221
+ SET_COMMAND_STRING = "SET"
222
+
223
+ def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, value: int):
224
+ self._encoding = encoding
225
+ self._offset = offset
226
+ self._value = value
227
+
228
+ def to_args(self) -> List[str]:
229
+ return [
230
+ self.SET_COMMAND_STRING,
231
+ self._encoding.to_arg(),
232
+ self._offset.to_arg(),
233
+ str(self._value),
234
+ ]
235
+
236
+
237
+ class BitFieldIncrBy(BitFieldSubCommands):
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.
249
+ INCRBY_COMMAND_STRING = "INCRBY"
250
+
251
+ def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, increment: int):
252
+ self._encoding = encoding
253
+ self._offset = offset
254
+ self._increment = increment
255
+
256
+ def to_args(self) -> List[str]:
257
+ return [
258
+ self.INCRBY_COMMAND_STRING,
259
+ self._encoding.to_arg(),
260
+ self._offset.to_arg(),
261
+ str(self._increment),
262
+ ]
263
+
264
+
265
+ class BitOverflowControl(Enum):
266
+ """
267
+ Enumeration specifying bit overflow controls for the `BITFIELD` command.
268
+ """
269
+
270
+ WRAP = "WRAP"
271
+ """
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
274
+ positive value.
275
+ """
276
+ SAT = "SAT"
277
+ """
278
+ Underflows remain set to the minimum value, and overflows remain set to the maximum value.
279
+ """
280
+ FAIL = "FAIL"
281
+ """
282
+ Returns `None` when overflows occur.
283
+ """
284
+
285
+
286
+ class BitFieldOverflow(BitFieldSubCommands):
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.
296
+ OVERFLOW_COMMAND_STRING = "OVERFLOW"
297
+
298
+ def __init__(self, overflow_control: BitOverflowControl):
299
+ self._overflow_control = overflow_control
300
+
301
+ def to_args(self) -> List[str]:
302
+ return [self.OVERFLOW_COMMAND_STRING, self._overflow_control.value]
303
+
304
+
305
+ def _create_bitfield_args(subcommands: List[BitFieldSubCommands]) -> List[str]:
306
+ args = []
307
+ for subcommand in subcommands:
308
+ args.extend(subcommand.to_args())
309
+
310
+ return args
311
+
312
+
313
+ def _create_bitfield_read_only_args(
314
+ subcommands: List[BitFieldGet],
315
+ ) -> List[str]:
316
+ args = []
317
+ for subcommand in subcommands:
318
+ args.extend(subcommand.to_args())
319
+
320
+ return args
@@ -0,0 +1,103 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+
3
+ from enum import Enum
4
+
5
+
6
+ class Limit:
7
+ """
8
+ Represents a limit argument for range queries in various commands.
9
+
10
+ The `LIMIT` argument is commonly used to specify a subset of results from the matching elements,
11
+ similar to the `LIMIT` clause in SQL (e.g., `SELECT LIMIT offset, count`).
12
+
13
+ This class can be utilized in multiple commands that support limit options,
14
+ such as [ZRANGE](https://valkey.io/commands/zrange), [SORT](https://valkey.io/commands/sort/) and others.
15
+
16
+ Args:
17
+ offset (int): The starting position of the range, zero based.
18
+ count (int): The maximum number of elements to include in the range.
19
+ A negative count returns all elements from the offset.
20
+
21
+ Examples:
22
+ >>> limit = Limit(0, 10) # Fetch the first 10 elements
23
+ >>> limit = Limit(5, -1) # Fetch all elements starting from the 5th element
24
+ """
25
+
26
+ def __init__(self, offset: int, count: int):
27
+ self.offset = offset
28
+ self.count = count
29
+
30
+
31
+ class OrderBy(Enum):
32
+ """
33
+ Enumeration representing sorting order options.
34
+
35
+ This enum is used for the following commands:
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
+
41
+ """
42
+
43
+ ASC = "ASC"
44
+ """
45
+ ASC: Sort in ascending order.
46
+ """
47
+
48
+ DESC = "DESC"
49
+ """
50
+ DESC: Sort in descending order.
51
+ """
52
+
53
+
54
+ class ListDirection(Enum):
55
+ """
56
+ Enumeration representing element popping or adding direction for List commands.
57
+ """
58
+
59
+ LEFT = "LEFT"
60
+ """
61
+ LEFT: Represents the option that elements should be popped from or added to the left side of a list.
62
+ """
63
+
64
+ RIGHT = "RIGHT"
65
+ """
66
+ RIGHT: Represents the option that elements should be popped from or added to the right side of a list.
67
+ """
68
+
69
+
70
+ class ObjectType(Enum):
71
+ """
72
+ Enumeration representing the data types supported by the database.
73
+ """
74
+
75
+ STRING = "String"
76
+ """
77
+ Represents a string data type.
78
+ """
79
+
80
+ LIST = "List"
81
+ """
82
+ Represents a list data type.
83
+ """
84
+
85
+ SET = "Set"
86
+ """
87
+ Represents a set data type.
88
+ """
89
+
90
+ ZSET = "ZSet"
91
+ """
92
+ Represents a sorted set data type.
93
+ """
94
+
95
+ HASH = "Hash"
96
+ """
97
+ Represents a hash data type.
98
+ """
99
+
100
+ STREAM = "Stream"
101
+ """
102
+ Represents a stream data type.
103
+ """