valkey-glide 1.3.5rc2__pp39-pypy39_pp73-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 +330 -0
- glide/async_commands/__init__.py +5 -0
- glide/async_commands/bitmap.py +311 -0
- glide/async_commands/cluster_commands.py +1294 -0
- glide/async_commands/command_args.py +102 -0
- glide/async_commands/core.py +7040 -0
- glide/async_commands/server_modules/ft.py +395 -0
- glide/async_commands/server_modules/ft_options/ft_aggregate_options.py +293 -0
- glide/async_commands/server_modules/ft_options/ft_constants.py +84 -0
- glide/async_commands/server_modules/ft_options/ft_create_options.py +409 -0
- glide/async_commands/server_modules/ft_options/ft_profile_options.py +108 -0
- glide/async_commands/server_modules/ft_options/ft_search_options.py +131 -0
- glide/async_commands/server_modules/glide_json.py +1255 -0
- glide/async_commands/server_modules/json_batch.py +790 -0
- glide/async_commands/sorted_set.py +402 -0
- glide/async_commands/standalone_commands.py +935 -0
- glide/async_commands/stream.py +442 -0
- glide/async_commands/transaction.py +5175 -0
- glide/config.py +590 -0
- glide/constants.py +120 -0
- glide/exceptions.py +62 -0
- glide/glide.pyi +36 -0
- glide/glide.pypy39-pp73-darwin.so +0 -0
- glide/glide_client.py +604 -0
- glide/logger.py +85 -0
- glide/protobuf/command_request_pb2.py +54 -0
- glide/protobuf/command_request_pb2.pyi +1164 -0
- glide/protobuf/connection_request_pb2.py +52 -0
- glide/protobuf/connection_request_pb2.pyi +292 -0
- glide/protobuf/response_pb2.py +32 -0
- glide/protobuf/response_pb2.pyi +101 -0
- glide/protobuf_codec.py +109 -0
- glide/py.typed +0 -0
- glide/routes.py +114 -0
- valkey_glide-1.3.5rc2.dist-info/METADATA +125 -0
- valkey_glide-1.3.5rc2.dist-info/RECORD +37 -0
- valkey_glide-1.3.5rc2.dist-info/WHEEL +4 -0
glide/__init__.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
from glide.async_commands.bitmap import (
|
|
4
|
+
BitEncoding,
|
|
5
|
+
BitFieldGet,
|
|
6
|
+
BitFieldIncrBy,
|
|
7
|
+
BitFieldOffset,
|
|
8
|
+
BitFieldOverflow,
|
|
9
|
+
BitFieldSet,
|
|
10
|
+
BitFieldSubCommands,
|
|
11
|
+
BitmapIndexType,
|
|
12
|
+
BitOffset,
|
|
13
|
+
BitOffsetMultiplier,
|
|
14
|
+
BitOverflowControl,
|
|
15
|
+
BitwiseOperation,
|
|
16
|
+
OffsetOptions,
|
|
17
|
+
SignedEncoding,
|
|
18
|
+
UnsignedEncoding,
|
|
19
|
+
)
|
|
20
|
+
from glide.async_commands.command_args import Limit, ListDirection, ObjectType, OrderBy
|
|
21
|
+
from glide.async_commands.core import (
|
|
22
|
+
ConditionalChange,
|
|
23
|
+
CoreCommands,
|
|
24
|
+
ExpireOptions,
|
|
25
|
+
ExpiryGetEx,
|
|
26
|
+
ExpirySet,
|
|
27
|
+
ExpiryType,
|
|
28
|
+
ExpiryTypeGetEx,
|
|
29
|
+
FlushMode,
|
|
30
|
+
FunctionRestorePolicy,
|
|
31
|
+
InfoSection,
|
|
32
|
+
InsertPosition,
|
|
33
|
+
OnlyIfEqual,
|
|
34
|
+
UpdateOptions,
|
|
35
|
+
)
|
|
36
|
+
from glide.async_commands.server_modules import ft, glide_json, json_batch
|
|
37
|
+
from glide.async_commands.server_modules.ft_options.ft_aggregate_options import (
|
|
38
|
+
FtAggregateApply,
|
|
39
|
+
FtAggregateClause,
|
|
40
|
+
FtAggregateFilter,
|
|
41
|
+
FtAggregateGroupBy,
|
|
42
|
+
FtAggregateLimit,
|
|
43
|
+
FtAggregateOptions,
|
|
44
|
+
FtAggregateReducer,
|
|
45
|
+
FtAggregateSortBy,
|
|
46
|
+
FtAggregateSortProperty,
|
|
47
|
+
)
|
|
48
|
+
from glide.async_commands.server_modules.ft_options.ft_create_options import (
|
|
49
|
+
DataType,
|
|
50
|
+
DistanceMetricType,
|
|
51
|
+
Field,
|
|
52
|
+
FieldType,
|
|
53
|
+
FtCreateOptions,
|
|
54
|
+
NumericField,
|
|
55
|
+
TagField,
|
|
56
|
+
TextField,
|
|
57
|
+
VectorAlgorithm,
|
|
58
|
+
VectorField,
|
|
59
|
+
VectorFieldAttributes,
|
|
60
|
+
VectorFieldAttributesFlat,
|
|
61
|
+
VectorFieldAttributesHnsw,
|
|
62
|
+
VectorType,
|
|
63
|
+
)
|
|
64
|
+
from glide.async_commands.server_modules.ft_options.ft_profile_options import (
|
|
65
|
+
FtProfileOptions,
|
|
66
|
+
QueryType,
|
|
67
|
+
)
|
|
68
|
+
from glide.async_commands.server_modules.ft_options.ft_search_options import (
|
|
69
|
+
FtSearchLimit,
|
|
70
|
+
FtSearchOptions,
|
|
71
|
+
ReturnField,
|
|
72
|
+
)
|
|
73
|
+
from glide.async_commands.server_modules.glide_json import (
|
|
74
|
+
JsonArrIndexOptions,
|
|
75
|
+
JsonArrPopOptions,
|
|
76
|
+
JsonGetOptions,
|
|
77
|
+
)
|
|
78
|
+
from glide.async_commands.sorted_set import (
|
|
79
|
+
AggregationType,
|
|
80
|
+
GeoSearchByBox,
|
|
81
|
+
GeoSearchByRadius,
|
|
82
|
+
GeoSearchCount,
|
|
83
|
+
GeospatialData,
|
|
84
|
+
GeoUnit,
|
|
85
|
+
InfBound,
|
|
86
|
+
LexBoundary,
|
|
87
|
+
RangeByIndex,
|
|
88
|
+
RangeByLex,
|
|
89
|
+
RangeByScore,
|
|
90
|
+
ScoreBoundary,
|
|
91
|
+
ScoreFilter,
|
|
92
|
+
)
|
|
93
|
+
from glide.async_commands.stream import (
|
|
94
|
+
ExclusiveIdBound,
|
|
95
|
+
IdBound,
|
|
96
|
+
MaxId,
|
|
97
|
+
MinId,
|
|
98
|
+
StreamAddOptions,
|
|
99
|
+
StreamClaimOptions,
|
|
100
|
+
StreamGroupOptions,
|
|
101
|
+
StreamPendingOptions,
|
|
102
|
+
StreamRangeBound,
|
|
103
|
+
StreamReadGroupOptions,
|
|
104
|
+
StreamReadOptions,
|
|
105
|
+
StreamTrimOptions,
|
|
106
|
+
TrimByMaxLen,
|
|
107
|
+
TrimByMinId,
|
|
108
|
+
)
|
|
109
|
+
from glide.async_commands.transaction import (
|
|
110
|
+
ClusterTransaction,
|
|
111
|
+
Transaction,
|
|
112
|
+
TTransaction,
|
|
113
|
+
)
|
|
114
|
+
from glide.config import (
|
|
115
|
+
AdvancedGlideClientConfiguration,
|
|
116
|
+
AdvancedGlideClusterClientConfiguration,
|
|
117
|
+
BackoffStrategy,
|
|
118
|
+
GlideClientConfiguration,
|
|
119
|
+
GlideClusterClientConfiguration,
|
|
120
|
+
NodeAddress,
|
|
121
|
+
PeriodicChecksManualInterval,
|
|
122
|
+
PeriodicChecksStatus,
|
|
123
|
+
ProtocolVersion,
|
|
124
|
+
ReadFrom,
|
|
125
|
+
ServerCredentials,
|
|
126
|
+
)
|
|
127
|
+
from glide.constants import (
|
|
128
|
+
OK,
|
|
129
|
+
TOK,
|
|
130
|
+
FtAggregateResponse,
|
|
131
|
+
FtInfoResponse,
|
|
132
|
+
FtProfileResponse,
|
|
133
|
+
FtSearchResponse,
|
|
134
|
+
TClusterResponse,
|
|
135
|
+
TEncodable,
|
|
136
|
+
TFunctionListResponse,
|
|
137
|
+
TFunctionStatsFullResponse,
|
|
138
|
+
TFunctionStatsSingleNodeResponse,
|
|
139
|
+
TJsonResponse,
|
|
140
|
+
TJsonUniversalResponse,
|
|
141
|
+
TResult,
|
|
142
|
+
TSingleNodeRoute,
|
|
143
|
+
TXInfoStreamFullResponse,
|
|
144
|
+
TXInfoStreamResponse,
|
|
145
|
+
)
|
|
146
|
+
from glide.exceptions import (
|
|
147
|
+
ClosingError,
|
|
148
|
+
ConfigurationError,
|
|
149
|
+
ConnectionError,
|
|
150
|
+
ExecAbortError,
|
|
151
|
+
GlideError,
|
|
152
|
+
RequestError,
|
|
153
|
+
TimeoutError,
|
|
154
|
+
)
|
|
155
|
+
from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient
|
|
156
|
+
from glide.logger import Level as LogLevel
|
|
157
|
+
from glide.logger import Logger
|
|
158
|
+
from glide.routes import (
|
|
159
|
+
AllNodes,
|
|
160
|
+
AllPrimaries,
|
|
161
|
+
ByAddressRoute,
|
|
162
|
+
RandomNode,
|
|
163
|
+
Route,
|
|
164
|
+
SlotIdRoute,
|
|
165
|
+
SlotKeyRoute,
|
|
166
|
+
SlotType,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
from .glide import ClusterScanCursor, Script
|
|
170
|
+
|
|
171
|
+
PubSubMsg = CoreCommands.PubSubMsg
|
|
172
|
+
|
|
173
|
+
__all__ = [
|
|
174
|
+
# Client
|
|
175
|
+
"GlideClient",
|
|
176
|
+
"GlideClusterClient",
|
|
177
|
+
"Transaction",
|
|
178
|
+
"ClusterTransaction",
|
|
179
|
+
"TGlideClient",
|
|
180
|
+
"TTransaction",
|
|
181
|
+
# Config
|
|
182
|
+
"AdvancedGlideClientConfiguration",
|
|
183
|
+
"AdvancedGlideClusterClientConfiguration",
|
|
184
|
+
"GlideClientConfiguration",
|
|
185
|
+
"GlideClusterClientConfiguration",
|
|
186
|
+
"BackoffStrategy",
|
|
187
|
+
"ReadFrom",
|
|
188
|
+
"ServerCredentials",
|
|
189
|
+
"NodeAddress",
|
|
190
|
+
"ProtocolVersion",
|
|
191
|
+
"PeriodicChecksManualInterval",
|
|
192
|
+
"PeriodicChecksStatus",
|
|
193
|
+
# Response
|
|
194
|
+
"OK",
|
|
195
|
+
"TClusterResponse",
|
|
196
|
+
"TEncodable",
|
|
197
|
+
"TFunctionListResponse",
|
|
198
|
+
"TFunctionStatsFullResponse",
|
|
199
|
+
"TFunctionStatsSingleNodeResponse",
|
|
200
|
+
"TJsonResponse",
|
|
201
|
+
"TJsonUniversalResponse",
|
|
202
|
+
"TOK",
|
|
203
|
+
"TResult",
|
|
204
|
+
"TXInfoStreamFullResponse",
|
|
205
|
+
"TXInfoStreamResponse",
|
|
206
|
+
"FtAggregateResponse",
|
|
207
|
+
"FtInfoResponse",
|
|
208
|
+
"FtProfileResponse",
|
|
209
|
+
"FtSearchResponse",
|
|
210
|
+
# Commands
|
|
211
|
+
"BitEncoding",
|
|
212
|
+
"BitFieldGet",
|
|
213
|
+
"BitFieldIncrBy",
|
|
214
|
+
"BitFieldOffset",
|
|
215
|
+
"BitFieldOverflow",
|
|
216
|
+
"BitFieldSet",
|
|
217
|
+
"BitFieldSubCommands",
|
|
218
|
+
"BitmapIndexType",
|
|
219
|
+
"BitOffset",
|
|
220
|
+
"BitOffsetMultiplier",
|
|
221
|
+
"BitOverflowControl",
|
|
222
|
+
"BitwiseOperation",
|
|
223
|
+
"OffsetOptions",
|
|
224
|
+
"SignedEncoding",
|
|
225
|
+
"UnsignedEncoding",
|
|
226
|
+
"Script",
|
|
227
|
+
"ScoreBoundary",
|
|
228
|
+
"ConditionalChange",
|
|
229
|
+
"OnlyIfEqual",
|
|
230
|
+
"ExpireOptions",
|
|
231
|
+
"ExpiryGetEx",
|
|
232
|
+
"ExpirySet",
|
|
233
|
+
"ExpiryType",
|
|
234
|
+
"ExpiryTypeGetEx",
|
|
235
|
+
"FlushMode",
|
|
236
|
+
"FunctionRestorePolicy",
|
|
237
|
+
"GeoSearchByBox",
|
|
238
|
+
"GeoSearchByRadius",
|
|
239
|
+
"GeoSearchCount",
|
|
240
|
+
"GeoUnit",
|
|
241
|
+
"GeospatialData",
|
|
242
|
+
"AggregationType",
|
|
243
|
+
"InfBound",
|
|
244
|
+
"InfoSection",
|
|
245
|
+
"InsertPosition",
|
|
246
|
+
"ft",
|
|
247
|
+
"LexBoundary",
|
|
248
|
+
"Limit",
|
|
249
|
+
"ListDirection",
|
|
250
|
+
"RangeByIndex",
|
|
251
|
+
"RangeByLex",
|
|
252
|
+
"RangeByScore",
|
|
253
|
+
"ScoreFilter",
|
|
254
|
+
"ObjectType",
|
|
255
|
+
"OrderBy",
|
|
256
|
+
"ExclusiveIdBound",
|
|
257
|
+
"IdBound",
|
|
258
|
+
"MaxId",
|
|
259
|
+
"MinId",
|
|
260
|
+
"StreamAddOptions",
|
|
261
|
+
"StreamClaimOptions",
|
|
262
|
+
"StreamGroupOptions",
|
|
263
|
+
"StreamPendingOptions",
|
|
264
|
+
"StreamReadGroupOptions",
|
|
265
|
+
"StreamRangeBound",
|
|
266
|
+
"StreamReadOptions",
|
|
267
|
+
"StreamTrimOptions",
|
|
268
|
+
"TrimByMaxLen",
|
|
269
|
+
"TrimByMinId",
|
|
270
|
+
"UpdateOptions",
|
|
271
|
+
"ClusterScanCursor",
|
|
272
|
+
# PubSub
|
|
273
|
+
"PubSubMsg",
|
|
274
|
+
# Json
|
|
275
|
+
"glide_json",
|
|
276
|
+
"json_batch",
|
|
277
|
+
"JsonGetOptions",
|
|
278
|
+
"JsonArrIndexOptions",
|
|
279
|
+
"JsonArrPopOptions",
|
|
280
|
+
# Logger
|
|
281
|
+
"Logger",
|
|
282
|
+
"LogLevel",
|
|
283
|
+
# Routes
|
|
284
|
+
"Route",
|
|
285
|
+
"SlotType",
|
|
286
|
+
"AllNodes",
|
|
287
|
+
"AllPrimaries",
|
|
288
|
+
"ByAddressRoute",
|
|
289
|
+
"RandomNode",
|
|
290
|
+
"SlotKeyRoute",
|
|
291
|
+
"SlotIdRoute",
|
|
292
|
+
"TSingleNodeRoute",
|
|
293
|
+
# Exceptions
|
|
294
|
+
"ClosingError",
|
|
295
|
+
"ConfigurationError",
|
|
296
|
+
"ConnectionError",
|
|
297
|
+
"ExecAbortError",
|
|
298
|
+
"GlideError",
|
|
299
|
+
"RequestError",
|
|
300
|
+
"TimeoutError",
|
|
301
|
+
# Ft
|
|
302
|
+
"DataType",
|
|
303
|
+
"DistanceMetricType",
|
|
304
|
+
"Field",
|
|
305
|
+
"FieldType",
|
|
306
|
+
"FtCreateOptions",
|
|
307
|
+
"NumericField",
|
|
308
|
+
"TagField",
|
|
309
|
+
"TextField",
|
|
310
|
+
"VectorAlgorithm",
|
|
311
|
+
"VectorField",
|
|
312
|
+
"VectorFieldAttributes",
|
|
313
|
+
"VectorFieldAttributesFlat",
|
|
314
|
+
"VectorFieldAttributesHnsw",
|
|
315
|
+
"VectorType",
|
|
316
|
+
"FtSearchLimit",
|
|
317
|
+
"ReturnField",
|
|
318
|
+
"FtSearchOptions",
|
|
319
|
+
"FtAggregateApply",
|
|
320
|
+
"FtAggregateFilter",
|
|
321
|
+
"FtAggregateClause",
|
|
322
|
+
"FtAggregateLimit",
|
|
323
|
+
"FtAggregateOptions",
|
|
324
|
+
"FtAggregateGroupBy",
|
|
325
|
+
"FtAggregateReducer",
|
|
326
|
+
"FtAggregateSortBy",
|
|
327
|
+
"FtAggregateSortProperty",
|
|
328
|
+
"FtProfileOptions",
|
|
329
|
+
"QueryType",
|
|
330
|
+
]
|
|
@@ -0,0 +1,311 @@
|
|
|
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
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
start: int,
|
|
29
|
+
end: Optional[int] = None,
|
|
30
|
+
index_type: Optional[BitmapIndexType] = None,
|
|
31
|
+
):
|
|
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
|
+
self.start = start
|
|
47
|
+
self.end = end
|
|
48
|
+
self.index_type = index_type
|
|
49
|
+
|
|
50
|
+
def to_args(self) -> List[str]:
|
|
51
|
+
args = [str(self.start)]
|
|
52
|
+
if self.end:
|
|
53
|
+
args.append(str(self.end))
|
|
54
|
+
if self.index_type is not None:
|
|
55
|
+
args.append(self.index_type.value)
|
|
56
|
+
|
|
57
|
+
return args
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class BitwiseOperation(Enum):
|
|
61
|
+
"""
|
|
62
|
+
Enumeration defining the bitwise operation to use in the `BITOP` command. Specifies the bitwise operation to
|
|
63
|
+
perform between the passed in keys.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
AND = "AND"
|
|
67
|
+
OR = "OR"
|
|
68
|
+
XOR = "XOR"
|
|
69
|
+
NOT = "NOT"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class BitEncoding(ABC):
|
|
73
|
+
"""
|
|
74
|
+
Abstract Base Class used to specify a signed or unsigned argument encoding for the `BITFIELD` or `BITFIELD_RO`
|
|
75
|
+
commands.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
@abstractmethod
|
|
79
|
+
def to_arg(self) -> str:
|
|
80
|
+
"""
|
|
81
|
+
Returns the encoding as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
|
|
82
|
+
commands.
|
|
83
|
+
"""
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class SignedEncoding(BitEncoding):
|
|
88
|
+
# Prefix specifying that the encoding is signed.
|
|
89
|
+
SIGNED_ENCODING_PREFIX = "i"
|
|
90
|
+
|
|
91
|
+
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
|
+
self._encoding = f"{self.SIGNED_ENCODING_PREFIX}{str(encoding_length)}"
|
|
99
|
+
|
|
100
|
+
def to_arg(self) -> str:
|
|
101
|
+
return self._encoding
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class UnsignedEncoding(BitEncoding):
|
|
105
|
+
# Prefix specifying that the encoding is unsigned.
|
|
106
|
+
UNSIGNED_ENCODING_PREFIX = "u"
|
|
107
|
+
|
|
108
|
+
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
|
+
self._encoding = f"{self.UNSIGNED_ENCODING_PREFIX}{str(encoding_length)}"
|
|
116
|
+
|
|
117
|
+
def to_arg(self) -> str:
|
|
118
|
+
return self._encoding
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class BitFieldOffset(ABC):
|
|
122
|
+
"""Abstract Base Class representing an offset for an array of bits for the `BITFIELD` or `BITFIELD_RO` commands."""
|
|
123
|
+
|
|
124
|
+
@abstractmethod
|
|
125
|
+
def to_arg(self) -> str:
|
|
126
|
+
"""
|
|
127
|
+
Returns the offset as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
|
|
128
|
+
commands.
|
|
129
|
+
"""
|
|
130
|
+
pass
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class BitOffset(BitFieldOffset):
|
|
134
|
+
def __init__(self, offset: int):
|
|
135
|
+
"""
|
|
136
|
+
Represents an offset in an array of bits for the `BITFIELD` or `BITFIELD_RO` commands. Must be greater than or
|
|
137
|
+
equal to 0.
|
|
138
|
+
|
|
139
|
+
For example, if we have the binary `01101001` with offset of 1 for an unsigned encoding of size 4, then the value
|
|
140
|
+
is 13 from `0(1101)001`.
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
offset (int): The bit index offset in the array of bits.
|
|
144
|
+
"""
|
|
145
|
+
self._offset = str(offset)
|
|
146
|
+
|
|
147
|
+
def to_arg(self) -> str:
|
|
148
|
+
return self._offset
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class BitOffsetMultiplier(BitFieldOffset):
|
|
152
|
+
# Prefix specifying that the offset uses an encoding multiplier.
|
|
153
|
+
OFFSET_MULTIPLIER_PREFIX = "#"
|
|
154
|
+
|
|
155
|
+
def __init__(self, offset: int):
|
|
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
|
+
Args:
|
|
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
|
+
self._offset = f"{self.OFFSET_MULTIPLIER_PREFIX}{str(offset)}"
|
|
169
|
+
|
|
170
|
+
def to_arg(self) -> str:
|
|
171
|
+
return self._offset
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class BitFieldSubCommands(ABC):
|
|
175
|
+
"""Abstract Base Class representing subcommands for the `BITFIELD` or `BITFIELD_RO` commands."""
|
|
176
|
+
|
|
177
|
+
@abstractmethod
|
|
178
|
+
def to_args(self) -> List[str]:
|
|
179
|
+
"""
|
|
180
|
+
Returns the subcommand as a list of string arguments to be used in the `BITFIELD` or `BITFIELD_RO` commands.
|
|
181
|
+
"""
|
|
182
|
+
pass
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class BitFieldGet(BitFieldSubCommands):
|
|
186
|
+
# "GET" subcommand string for use in the `BITFIELD` or `BITFIELD_RO` commands.
|
|
187
|
+
GET_COMMAND_STRING = "GET"
|
|
188
|
+
|
|
189
|
+
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
|
+
self._encoding = encoding
|
|
198
|
+
self._offset = offset
|
|
199
|
+
|
|
200
|
+
def to_args(self) -> List[str]:
|
|
201
|
+
return [self.GET_COMMAND_STRING, self._encoding.to_arg(), self._offset.to_arg()]
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class BitFieldSet(BitFieldSubCommands):
|
|
205
|
+
# "SET" subcommand string for use in the `BITFIELD` command.
|
|
206
|
+
SET_COMMAND_STRING = "SET"
|
|
207
|
+
|
|
208
|
+
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
|
+
self._encoding = encoding
|
|
218
|
+
self._offset = offset
|
|
219
|
+
self._value = value
|
|
220
|
+
|
|
221
|
+
def to_args(self) -> List[str]:
|
|
222
|
+
return [
|
|
223
|
+
self.SET_COMMAND_STRING,
|
|
224
|
+
self._encoding.to_arg(),
|
|
225
|
+
self._offset.to_arg(),
|
|
226
|
+
str(self._value),
|
|
227
|
+
]
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class BitFieldIncrBy(BitFieldSubCommands):
|
|
231
|
+
# "INCRBY" subcommand string for use in the `BITFIELD` command.
|
|
232
|
+
INCRBY_COMMAND_STRING = "INCRBY"
|
|
233
|
+
|
|
234
|
+
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
|
+
self._encoding = encoding
|
|
245
|
+
self._offset = offset
|
|
246
|
+
self._increment = increment
|
|
247
|
+
|
|
248
|
+
def to_args(self) -> List[str]:
|
|
249
|
+
return [
|
|
250
|
+
self.INCRBY_COMMAND_STRING,
|
|
251
|
+
self._encoding.to_arg(),
|
|
252
|
+
self._offset.to_arg(),
|
|
253
|
+
str(self._increment),
|
|
254
|
+
]
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
class BitOverflowControl(Enum):
|
|
258
|
+
"""
|
|
259
|
+
Enumeration specifying bit overflow controls for the `BITFIELD` command.
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
WRAP = "WRAP"
|
|
263
|
+
"""
|
|
264
|
+
Performs modulo when overflows occur with unsigned encoding. When overflows occur with signed encoding, the value
|
|
265
|
+
restarts at the most negative value. When underflows occur with signed encoding, the value restarts at the most
|
|
266
|
+
positive value.
|
|
267
|
+
"""
|
|
268
|
+
SAT = "SAT"
|
|
269
|
+
"""
|
|
270
|
+
Underflows remain set to the minimum value, and overflows remain set to the maximum value.
|
|
271
|
+
"""
|
|
272
|
+
FAIL = "FAIL"
|
|
273
|
+
"""
|
|
274
|
+
Returns `None` when overflows occur.
|
|
275
|
+
"""
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
class BitFieldOverflow(BitFieldSubCommands):
|
|
279
|
+
# "OVERFLOW" subcommand string for use in the `BITFIELD` command.
|
|
280
|
+
OVERFLOW_COMMAND_STRING = "OVERFLOW"
|
|
281
|
+
|
|
282
|
+
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
|
+
self._overflow_control = overflow_control
|
|
291
|
+
|
|
292
|
+
def to_args(self) -> List[str]:
|
|
293
|
+
return [self.OVERFLOW_COMMAND_STRING, self._overflow_control.value]
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _create_bitfield_args(subcommands: List[BitFieldSubCommands]) -> List[str]:
|
|
297
|
+
args = []
|
|
298
|
+
for subcommand in subcommands:
|
|
299
|
+
args.extend(subcommand.to_args())
|
|
300
|
+
|
|
301
|
+
return args
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _create_bitfield_read_only_args(
|
|
305
|
+
subcommands: List[BitFieldGet],
|
|
306
|
+
) -> List[str]:
|
|
307
|
+
args = []
|
|
308
|
+
for subcommand in subcommands:
|
|
309
|
+
args.extend(subcommand.to_args())
|
|
310
|
+
|
|
311
|
+
return args
|