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,93 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+
3
+ from typing import List, Optional
4
+
5
+ from glide_shared.constants import TEncodable
6
+
7
+
8
+ class JsonArrIndexOptions:
9
+ """
10
+ Options for the `JSON.ARRINDEX` command.
11
+
12
+ Args:
13
+ start (int): The inclusive start index from which the search begins. Defaults to None.
14
+ end (Optional[int]): The exclusive end index where the search stops. Defaults to None.
15
+
16
+ Note:
17
+ - If `start` is greater than `end`, the command returns `-1` to indicate that the value was not found.
18
+ - Indices that exceed the array bounds are automatically adjusted to the nearest valid position.
19
+ """
20
+
21
+ def __init__(self, start: int, end: Optional[int] = None):
22
+ self.start = start
23
+ self.end = end
24
+
25
+ def to_args(self) -> List[str]:
26
+ """
27
+ Get the options as a list of arguments for the JSON.ARRINDEX command.
28
+
29
+ Returns:
30
+ List[str]: A list containing the start and end indices if specified.
31
+ """
32
+ args = [str(self.start)]
33
+ if self.end is not None:
34
+ args.append(str(self.end))
35
+ return args
36
+
37
+
38
+ class JsonArrPopOptions:
39
+ """
40
+ Options for the JSON.ARRPOP command.
41
+
42
+ Args:
43
+ path (TEncodable): The path within the JSON document.
44
+ index (Optional[int]): The index of the element to pop. If not specified, will pop the last element.
45
+ Out of boundary indexes are rounded to their respective array boundaries. Defaults to None.
46
+ """
47
+
48
+ def __init__(self, path: TEncodable, index: Optional[int] = None):
49
+ self.path = path
50
+ self.index = index
51
+
52
+ def to_args(self) -> List[TEncodable]:
53
+ """
54
+ Get the options as a list of arguments for the `JSON.ARRPOP` command.
55
+
56
+ Returns:
57
+ List[TEncodable]: A list containing the path and, if specified, the index.
58
+ """
59
+ args = [self.path]
60
+ if self.index is not None:
61
+ args.append(str(self.index))
62
+ return args
63
+
64
+
65
+ class JsonGetOptions:
66
+ """
67
+ Represents options for formatting JSON data, to be used in the [JSON.GET](https://valkey.io/commands/json.get/) command.
68
+
69
+ Args:
70
+ indent (Optional[str]): Sets an indentation string for nested levels. Defaults to None.
71
+ newline (Optional[str]): Sets a string that's printed at the end of each line. Defaults to None.
72
+ space (Optional[str]): Sets a string that's put between a key and a value. Defaults to None.
73
+ """
74
+
75
+ def __init__(
76
+ self,
77
+ indent: Optional[str] = None,
78
+ newline: Optional[str] = None,
79
+ space: Optional[str] = None,
80
+ ):
81
+ self.indent = indent
82
+ self.new_line = newline
83
+ self.space = space
84
+
85
+ def get_options(self) -> List[str]:
86
+ args = []
87
+ if self.indent:
88
+ args.extend(["INDENT", self.indent])
89
+ if self.new_line:
90
+ args.extend(["NEWLINE", self.new_line])
91
+ if self.space:
92
+ args.extend(["SPACE", self.space])
93
+ return args
@@ -0,0 +1,412 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+
3
+ from enum import Enum
4
+ from typing import List, Optional, Tuple, Union, cast
5
+
6
+ from glide_shared.commands.command_args import Limit, OrderBy
7
+ from glide_shared.constants import TEncodable
8
+
9
+
10
+ class InfBound(Enum):
11
+ """
12
+ Enumeration representing numeric and lexicographic positive and negative infinity bounds for sorted set.
13
+ """
14
+
15
+ POS_INF = {"score_arg": "+inf", "lex_arg": "+"}
16
+ """
17
+ Positive infinity bound for sorted set.
18
+
19
+ `score_arg`: represents numeric positive infinity (+inf).
20
+
21
+ `lex_arg`: represents lexicographic positive infinity (+).
22
+ """
23
+ NEG_INF = {"score_arg": "-inf", "lex_arg": "-"}
24
+ """
25
+ Negative infinity bound for sorted set.
26
+
27
+ `score_arg`: represents numeric negative infinity (-inf).
28
+
29
+ `lex_arg`: represents lexicographic negative infinity (-).
30
+ """
31
+
32
+
33
+ class AggregationType(Enum):
34
+ """
35
+ Enumeration representing aggregation types for `ZINTERSTORE` and `ZUNIONSTORE` sorted set commands.
36
+ """
37
+
38
+ SUM = "SUM"
39
+ """
40
+ Represents aggregation by summing the scores of elements across inputs where they exist.
41
+ """
42
+ MIN = "MIN"
43
+ """
44
+ Represents aggregation by selecting the minimum score of an element across inputs where it exists.
45
+ """
46
+ MAX = "MAX"
47
+ """
48
+ Represents aggregation by selecting the maximum score of an element across inputs where it exists.
49
+ """
50
+
51
+
52
+ class ScoreFilter(Enum):
53
+ """
54
+ Defines which elements to pop from a sorted set.
55
+
56
+ ScoreFilter is a mandatory option for [ZMPOP](https://valkey.io/commands/zmpop)
57
+ and [BZMPOP](https://valkey.io/commands/bzmpop).
58
+ """
59
+
60
+ MIN = "MIN"
61
+ """
62
+ Pop elements with the lowest scores.
63
+ """
64
+ MAX = "MAX"
65
+ """
66
+ Pop elements with the highest scores.
67
+ """
68
+
69
+
70
+ class ScoreBoundary:
71
+ """
72
+ Represents a specific numeric score boundary in a sorted set.
73
+
74
+ Args:
75
+ value (float): The score value.
76
+ is_inclusive (bool): Whether the score value is inclusive. Defaults to True.
77
+ """
78
+
79
+ def __init__(self, value: float, is_inclusive: bool = True):
80
+ # Convert the score boundary to Valkey protocol format
81
+ self.value = str(value) if is_inclusive else f"({value}"
82
+
83
+
84
+ class LexBoundary:
85
+ """
86
+ Represents a specific lexicographic boundary in a sorted set.
87
+
88
+ Args:
89
+ value (str): The lex value.
90
+ is_inclusive (bool): Whether the score value is inclusive. Defaults to True.
91
+ """
92
+
93
+ def __init__(self, value: str, is_inclusive: bool = True):
94
+ # Convert the lexicographic boundary to Valkey protocol format
95
+ self.value = f"[{value}" if is_inclusive else f"({value}"
96
+
97
+
98
+ class RangeByIndex:
99
+ """
100
+ Represents a range by index (rank) in a sorted set.
101
+
102
+ The `start` and `end` arguments represent zero-based indexes.
103
+
104
+ Attributes:
105
+ start (int): The start index of the range.
106
+ end (int): The end index of the range.
107
+ """
108
+
109
+ def __init__(self, start: int, end: int):
110
+ self.start = start
111
+ self.end = end
112
+
113
+
114
+ class RangeByScore:
115
+ """
116
+ Represents a range by score in a sorted set.
117
+
118
+ The `start` and `end` arguments represent score boundaries.
119
+
120
+ Attributes:
121
+ start (Union[InfBound, ScoreBoundary]): The start score boundary.
122
+ end (Union[InfBound, ScoreBoundary]): The end score boundary.
123
+ limit (Optional[Limit]): The limit argument for a range query. Defaults to None. See `Limit`
124
+ class for more information.
125
+ """
126
+
127
+ def __init__(
128
+ self,
129
+ start: Union[InfBound, ScoreBoundary],
130
+ end: Union[InfBound, ScoreBoundary],
131
+ limit: Optional[Limit] = None,
132
+ ):
133
+ self.start = (
134
+ start.value["score_arg"] if isinstance(start, InfBound) else start.value
135
+ )
136
+ self.end = end.value["score_arg"] if isinstance(end, InfBound) else end.value
137
+ self.limit = limit
138
+
139
+
140
+ class RangeByLex:
141
+ """
142
+ Represents a range by lexicographical order in a sorted set.
143
+
144
+ The `start` and `end` arguments represent lexicographical boundaries.
145
+
146
+ Attributes:
147
+ start (Union[InfBound, LexBoundary]): The start lexicographic boundary.
148
+ end (Union[InfBound, LexBoundary]): The end lexicographic boundary.
149
+ limit (Optional[Limit]): The limit argument for a range query. Defaults to None. See `Limit` class
150
+ for more information.
151
+ """
152
+
153
+ def __init__(
154
+ self,
155
+ start: Union[InfBound, LexBoundary],
156
+ end: Union[InfBound, LexBoundary],
157
+ limit: Optional[Limit] = None,
158
+ ):
159
+ self.start = (
160
+ start.value["lex_arg"] if isinstance(start, InfBound) else start.value
161
+ )
162
+ self.end = end.value["lex_arg"] if isinstance(end, InfBound) else end.value
163
+ self.limit = limit
164
+
165
+
166
+ class GeospatialData:
167
+ """
168
+ Represents a geographic position defined by longitude and latitude.
169
+
170
+ The exact limits, as specified by EPSG:900913 / EPSG:3785 / OSGEO:41001 are the following:
171
+
172
+ - Valid longitudes are from -180 to 180 degrees.
173
+ - Valid latitudes are from -85.05112878 to 85.05112878 degrees.
174
+
175
+ Attributes:
176
+ longitude (float): The longitude coordinate.
177
+ latitude (float): The latitude coordinate.
178
+ """
179
+
180
+ def __init__(self, longitude: float, latitude: float):
181
+ self.longitude = longitude
182
+ self.latitude = latitude
183
+
184
+
185
+ class GeoUnit(Enum):
186
+ """
187
+ Enumeration representing distance units options for the `GEODIST` command.
188
+ """
189
+
190
+ METERS = "m"
191
+ """
192
+ Represents distance in meters.
193
+ """
194
+ KILOMETERS = "km"
195
+ """
196
+ Represents distance in kilometers.
197
+ """
198
+ MILES = "mi"
199
+ """
200
+ Represents distance in miles.
201
+ """
202
+ FEET = "ft"
203
+ """
204
+ Represents distance in feet.
205
+ """
206
+
207
+
208
+ class GeoSearchByRadius:
209
+ """
210
+ Represents search criteria of searching within a certain radius from a specified point.
211
+
212
+ Attributes:
213
+ radius (float): Radius of the search area.
214
+ unit (GeoUnit): Unit of the radius. See `GeoUnit`.
215
+ """
216
+
217
+ def __init__(self, radius: float, unit: GeoUnit):
218
+ """
219
+ Initialize the search criteria.
220
+ """
221
+ self.radius = radius
222
+ self.unit = unit
223
+
224
+ def to_args(self) -> List[str]:
225
+ """
226
+ Convert the search criteria to the corresponding part of the command.
227
+
228
+ Returns:
229
+ List[str]: List representation of the search criteria.
230
+ """
231
+ return ["BYRADIUS", str(self.radius), self.unit.value]
232
+
233
+
234
+ class GeoSearchByBox:
235
+ """
236
+ Represents search criteria of searching within a specified rectangular area.
237
+
238
+ Attributes:
239
+ width (float): Width of the bounding box.
240
+ height (float): Height of the bounding box
241
+ unit (GeoUnit): Unit of the radius. See `GeoUnit`.
242
+ """
243
+
244
+ def __init__(self, width: float, height: float, unit: GeoUnit):
245
+ """
246
+ Initialize the search criteria.
247
+ """
248
+ self.width = width
249
+ self.height = height
250
+ self.unit = unit
251
+
252
+ def to_args(self) -> List[str]:
253
+ """
254
+ Convert the search criteria to the corresponding part of the command.
255
+
256
+ Returns:
257
+ List[str]: List representation of the search criteria.
258
+ """
259
+ return ["BYBOX", str(self.width), str(self.height), self.unit.value]
260
+
261
+
262
+ class GeoSearchCount:
263
+ """
264
+ Represents the count option for limiting the number of results in a GeoSearch.
265
+
266
+ Attributes:
267
+ count (int): The maximum number of results to return.
268
+ any_option (bool): Whether to allow returning as enough matches are found.
269
+ This means that the results returned may not be the ones closest to the specified point. Default to False.
270
+ """
271
+
272
+ def __init__(self, count: int, any_option: bool = False):
273
+ """
274
+ Initialize the count option.
275
+ """
276
+ self.count = count
277
+ self.any_option = any_option
278
+
279
+ def to_args(self) -> List[str]:
280
+ """
281
+ Convert the count option to the corresponding part of the command.
282
+
283
+ Returns:
284
+ List[str]: List representation of the count option.
285
+ """
286
+ if self.any_option:
287
+ return ["COUNT", str(self.count), "ANY"]
288
+ return ["COUNT", str(self.count)]
289
+
290
+
291
+ def _create_zrange_args(
292
+ key: TEncodable,
293
+ range_query: Union[RangeByLex, RangeByScore, RangeByIndex],
294
+ reverse: bool,
295
+ with_scores: bool,
296
+ destination: Optional[TEncodable] = None,
297
+ ) -> List[TEncodable]:
298
+ args = [destination] if destination else []
299
+ args += [key, str(range_query.start), str(range_query.end)]
300
+
301
+ if isinstance(range_query, RangeByScore):
302
+ args.append("BYSCORE")
303
+ elif isinstance(range_query, RangeByLex):
304
+ args.append("BYLEX")
305
+ if reverse:
306
+ args.append("REV")
307
+ if hasattr(range_query, "limit") and range_query.limit is not None:
308
+ args.extend(
309
+ [
310
+ "LIMIT",
311
+ str(range_query.limit.offset),
312
+ str(range_query.limit.count),
313
+ ]
314
+ )
315
+ if with_scores:
316
+ args.append("WITHSCORES")
317
+
318
+ return args
319
+
320
+
321
+ def separate_keys(
322
+ keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
323
+ ) -> Tuple[List[TEncodable], List[TEncodable]]:
324
+ """
325
+ Returns separate lists of keys and weights in case of weighted keys.
326
+ """
327
+ if not keys:
328
+ return [], []
329
+
330
+ key_list: List[TEncodable] = []
331
+ weight_list: List[TEncodable] = []
332
+
333
+ if isinstance(keys[0], tuple):
334
+ for item in keys:
335
+ key = item[0]
336
+ weight = item[1]
337
+ key_list.append(cast(TEncodable, key))
338
+ weight_list.append(cast(TEncodable, str(weight)))
339
+ else:
340
+ key_list.extend(cast(List[TEncodable], keys))
341
+
342
+ return key_list, weight_list
343
+
344
+
345
+ def _create_zinter_zunion_cmd_args(
346
+ keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
347
+ aggregation_type: Optional[AggregationType] = None,
348
+ destination: Optional[TEncodable] = None,
349
+ ) -> List[TEncodable]:
350
+ args: List[TEncodable] = []
351
+
352
+ if destination:
353
+ args.append(destination)
354
+
355
+ args.append(str(len(keys)))
356
+
357
+ only_keys, weights = separate_keys(keys)
358
+
359
+ args.extend(only_keys)
360
+
361
+ if weights:
362
+ args.append("WEIGHTS")
363
+ args.extend(weights)
364
+
365
+ if aggregation_type:
366
+ args.append("AGGREGATE")
367
+ args.append(aggregation_type.value)
368
+
369
+ return args
370
+
371
+
372
+ def _create_geosearch_args(
373
+ keys: List[TEncodable],
374
+ search_from: Union[str, bytes, GeospatialData],
375
+ search_by: Union[GeoSearchByRadius, GeoSearchByBox],
376
+ order_by: Optional[OrderBy] = None,
377
+ count: Optional[GeoSearchCount] = None,
378
+ with_coord: bool = False,
379
+ with_dist: bool = False,
380
+ with_hash: bool = False,
381
+ store_dist: bool = False,
382
+ ) -> List[TEncodable]:
383
+ args: List[TEncodable] = keys
384
+ if isinstance(search_from, (str, bytes)):
385
+ args.extend(["FROMMEMBER", search_from])
386
+ else:
387
+ args.extend(
388
+ [
389
+ "FROMLONLAT",
390
+ str(search_from.longitude),
391
+ str(search_from.latitude),
392
+ ]
393
+ )
394
+
395
+ args.extend(search_by.to_args())
396
+
397
+ if order_by:
398
+ args.append(order_by.value)
399
+ if count:
400
+ args.extend(count.to_args())
401
+
402
+ if with_coord:
403
+ args.append("WITHCOORD")
404
+ if with_dist:
405
+ args.append("WITHDIST")
406
+ if with_hash:
407
+ args.append("WITHHASH")
408
+
409
+ if store_dist:
410
+ args.append("STOREDIST")
411
+
412
+ return args