valkey-glide 1.3.5__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.

Files changed (37) hide show
  1. glide/__init__.py +330 -0
  2. glide/async_commands/__init__.py +5 -0
  3. glide/async_commands/bitmap.py +311 -0
  4. glide/async_commands/cluster_commands.py +1294 -0
  5. glide/async_commands/command_args.py +102 -0
  6. glide/async_commands/core.py +7040 -0
  7. glide/async_commands/server_modules/ft.py +395 -0
  8. glide/async_commands/server_modules/ft_options/ft_aggregate_options.py +293 -0
  9. glide/async_commands/server_modules/ft_options/ft_constants.py +84 -0
  10. glide/async_commands/server_modules/ft_options/ft_create_options.py +409 -0
  11. glide/async_commands/server_modules/ft_options/ft_profile_options.py +108 -0
  12. glide/async_commands/server_modules/ft_options/ft_search_options.py +131 -0
  13. glide/async_commands/server_modules/glide_json.py +1255 -0
  14. glide/async_commands/server_modules/json_batch.py +790 -0
  15. glide/async_commands/sorted_set.py +402 -0
  16. glide/async_commands/standalone_commands.py +935 -0
  17. glide/async_commands/stream.py +442 -0
  18. glide/async_commands/transaction.py +5175 -0
  19. glide/config.py +590 -0
  20. glide/constants.py +120 -0
  21. glide/exceptions.py +62 -0
  22. glide/glide.pyi +36 -0
  23. glide/glide.pypy39-pp73-darwin.so +0 -0
  24. glide/glide_client.py +604 -0
  25. glide/logger.py +85 -0
  26. glide/protobuf/command_request_pb2.py +54 -0
  27. glide/protobuf/command_request_pb2.pyi +1164 -0
  28. glide/protobuf/connection_request_pb2.py +52 -0
  29. glide/protobuf/connection_request_pb2.pyi +292 -0
  30. glide/protobuf/response_pb2.py +32 -0
  31. glide/protobuf/response_pb2.pyi +101 -0
  32. glide/protobuf_codec.py +109 -0
  33. glide/py.typed +0 -0
  34. glide/routes.py +114 -0
  35. valkey_glide-1.3.5.dist-info/METADATA +125 -0
  36. valkey_glide-1.3.5.dist-info/RECORD +37 -0
  37. valkey_glide-1.3.5.dist-info/WHEEL +4 -0
@@ -0,0 +1,442 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+ from __future__ import annotations
3
+
4
+ from abc import ABC, abstractmethod
5
+ from typing import List, Optional, Union
6
+
7
+ from glide.constants import TEncodable
8
+
9
+
10
+ class StreamTrimOptions(ABC):
11
+ """
12
+ Abstract base class for stream trim options.
13
+ """
14
+
15
+ @abstractmethod
16
+ def __init__(
17
+ self,
18
+ exact: bool,
19
+ threshold: Union[TEncodable, int],
20
+ method: str,
21
+ limit: Optional[int] = None,
22
+ ):
23
+ """
24
+ Initialize stream trim options.
25
+
26
+ Args:
27
+ exact (bool): If `true`, the stream will be trimmed exactly.
28
+ Otherwise the stream will be trimmed in a near-exact manner, which is more efficient.
29
+ threshold (Union[TEncodable, int]): Threshold for trimming.
30
+ method (str): Method for trimming (e.g., MINID, MAXLEN).
31
+ limit (Optional[int]): Max number of entries to be trimmed. Defaults to None.
32
+ Note: If `exact` is set to `True`, `limit` cannot be specified.
33
+ """
34
+ if exact and limit:
35
+ raise ValueError(
36
+ "If `exact` is set to `True`, `limit` cannot be specified."
37
+ )
38
+ self.exact = exact
39
+ self.threshold = threshold
40
+ self.method = method
41
+ self.limit = limit
42
+
43
+ def to_args(self) -> List[str]:
44
+ """
45
+ Convert options to arguments for the command.
46
+
47
+ Returns:
48
+ List[str]: List of arguments for the command.
49
+ """
50
+ option_args = [
51
+ self.method,
52
+ "=" if self.exact else "~",
53
+ str(self.threshold),
54
+ ]
55
+ if self.limit is not None:
56
+ option_args.extend(["LIMIT", str(self.limit)])
57
+ return option_args
58
+
59
+
60
+ class TrimByMinId(StreamTrimOptions):
61
+ """
62
+ Stream trim option to trim by minimum ID.
63
+ """
64
+
65
+ def __init__(self, exact: bool, threshold: TEncodable, limit: Optional[int] = None):
66
+ """
67
+ Initialize trim option by minimum ID.
68
+
69
+ Args:
70
+ exact (bool): If `true`, the stream will be trimmed exactly.
71
+ Otherwise the stream will be trimmed in a near-exact manner, which is more efficient.
72
+ threshold (TEncodable): Threshold for trimming by minimum ID.
73
+ limit (Optional[int]): Max number of entries to be trimmed. Defaults to None.
74
+ Note: If `exact` is set to `True`, `limit` cannot be specified.
75
+ """
76
+ super().__init__(exact, threshold, "MINID", limit)
77
+
78
+
79
+ class TrimByMaxLen(StreamTrimOptions):
80
+ """
81
+ Stream trim option to trim by maximum length.
82
+ """
83
+
84
+ def __init__(self, exact: bool, threshold: int, limit: Optional[int] = None):
85
+ """
86
+ Initialize trim option by maximum length.
87
+
88
+ Args:
89
+ exact (bool): If `true`, the stream will be trimmed exactly.
90
+ Otherwise the stream will be trimmed in a near-exact manner, which is more efficient.
91
+ threshold (int): Threshold for trimming by maximum length.
92
+ limit (Optional[int]): Max number of entries to be trimmed. Defaults to None.
93
+ Note: If `exact` is set to `True`, `limit` cannot be specified.
94
+ """
95
+ super().__init__(exact, threshold, "MAXLEN", limit)
96
+
97
+
98
+ class StreamAddOptions:
99
+ """
100
+ Options for adding entries to a stream.
101
+ """
102
+
103
+ def __init__(
104
+ self,
105
+ id: Optional[TEncodable] = None,
106
+ make_stream: bool = True,
107
+ trim: Optional[StreamTrimOptions] = None,
108
+ ):
109
+ """
110
+ Initialize stream add options.
111
+
112
+ Args:
113
+ id (Optional[TEncodable]): ID for the new entry. If set, the new entry will be added with this ID. If not specified, '*' is used.
114
+ make_stream (bool, optional): If set to False, a new stream won't be created if no stream matches the given key.
115
+ trim (Optional[StreamTrimOptions]): If set, the add operation will also trim the older entries in the stream. See `StreamTrimOptions`.
116
+ """
117
+ self.id = id
118
+ self.make_stream = make_stream
119
+ self.trim = trim
120
+
121
+ def to_args(self) -> List[TEncodable]:
122
+ """
123
+ Convert options to arguments for the command.
124
+
125
+ Returns:
126
+ List[str]: List of arguments for the command.
127
+ """
128
+ option_args: List[TEncodable] = []
129
+ if not self.make_stream:
130
+ option_args.append("NOMKSTREAM")
131
+ if self.trim:
132
+ option_args.extend(self.trim.to_args())
133
+ option_args.append(self.id if self.id else "*")
134
+
135
+ return option_args
136
+
137
+
138
+ class StreamRangeBound(ABC):
139
+ """
140
+ Abstract Base Class used in the `XPENDING`, `XRANGE`, and `XREVRANGE` commands to specify the starting and ending
141
+ range bound for the stream search by stream entry ID.
142
+ """
143
+
144
+ @abstractmethod
145
+ def to_arg(self) -> TEncodable:
146
+ """
147
+ Returns the stream range bound as a string argument to be used in the `XRANGE` or `XREVRANGE` commands.
148
+ """
149
+ pass
150
+
151
+
152
+ class MinId(StreamRangeBound):
153
+ """
154
+ Stream ID boundary used to specify the minimum stream entry ID. Can be used in the `XRANGE` or `XREVRANGE` commands
155
+ to get the first stream ID.
156
+ """
157
+
158
+ MIN_RANGE_VALKEY_API = "-"
159
+
160
+ def to_arg(self) -> str:
161
+ return self.MIN_RANGE_VALKEY_API
162
+
163
+
164
+ class MaxId(StreamRangeBound):
165
+ """
166
+ Stream ID boundary used to specify the maximum stream entry ID. Can be used in the `XRANGE` or `XREVRANGE` commands
167
+ to get the last stream ID.
168
+ """
169
+
170
+ MAX_RANGE_VALKEY_API = "+"
171
+
172
+ def to_arg(self) -> str:
173
+ return self.MAX_RANGE_VALKEY_API
174
+
175
+
176
+ class IdBound(StreamRangeBound):
177
+ """
178
+ Inclusive (closed) stream ID boundary used to specify a range of IDs to search. Stream ID bounds can be complete
179
+ with a timestamp and sequence number separated by a dash ("-"), for example "1526985054069-0". Stream ID bounds can
180
+ also be incomplete, with just a timestamp.
181
+ """
182
+
183
+ @staticmethod
184
+ def from_timestamp(timestamp: int) -> IdBound:
185
+ """
186
+ Creates an incomplete stream ID boundary without the sequence number for a range search.
187
+
188
+ Args:
189
+ timestamp (int): The stream ID timestamp.
190
+ """
191
+ return IdBound(str(timestamp))
192
+
193
+ def __init__(self, stream_id: TEncodable):
194
+ """
195
+ Creates a stream ID boundary for a range search.
196
+
197
+ Args:
198
+ stream_id (str): The stream ID.
199
+ """
200
+ self.stream_id = stream_id
201
+
202
+ def to_arg(self) -> TEncodable:
203
+ return self.stream_id
204
+
205
+
206
+ class ExclusiveIdBound(StreamRangeBound):
207
+ """
208
+ Exclusive (open) stream ID boundary used to specify a range of IDs to search. Stream ID bounds can be complete with
209
+ a timestamp and sequence number separated by a dash ("-"), for example "1526985054069-0". Stream ID bounds can also
210
+ be incomplete, with just a timestamp.
211
+
212
+ Since: Valkey version 6.2.0.
213
+ """
214
+
215
+ EXCLUSIVE_BOUND_VALKEY_API = "("
216
+
217
+ @staticmethod
218
+ def from_timestamp(timestamp: int) -> ExclusiveIdBound:
219
+ """
220
+ Creates an incomplete stream ID boundary without the sequence number for a range search.
221
+
222
+ Args:
223
+ timestamp (int): The stream ID timestamp.
224
+ """
225
+ return ExclusiveIdBound(str(timestamp))
226
+
227
+ def __init__(self, stream_id: TEncodable):
228
+ """
229
+ Creates a stream ID boundary for a range search.
230
+
231
+ Args:
232
+ stream_id (TEncodable): The stream ID.
233
+ """
234
+ if isinstance(stream_id, bytes):
235
+ stream_id = stream_id.decode("utf-8")
236
+ self.stream_id = f"{self.EXCLUSIVE_BOUND_VALKEY_API}{stream_id}"
237
+
238
+ def to_arg(self) -> TEncodable:
239
+ return self.stream_id
240
+
241
+
242
+ class StreamReadOptions:
243
+ READ_COUNT_VALKEY_API = "COUNT"
244
+ READ_BLOCK_VALKEY_API = "BLOCK"
245
+
246
+ def __init__(self, block_ms: Optional[int] = None, count: Optional[int] = None):
247
+ """
248
+ Options for reading entries from streams. Can be used as an optional argument to `XREAD`.
249
+
250
+ Args:
251
+ block_ms (Optional[int]): If provided, the request will be blocked for the set amount of milliseconds or
252
+ until the server has the required number of entries. Equivalent to `BLOCK` in the Valkey API.
253
+ count (Optional[int]): The maximum number of elements requested. Equivalent to `COUNT` in the Valkey API.
254
+ """
255
+ self.block_ms = block_ms
256
+ self.count = count
257
+
258
+ def to_args(self) -> List[TEncodable]:
259
+ """
260
+ Returns the options as a list of string arguments to be used in the `XREAD` command.
261
+
262
+ Returns:
263
+ List[TEncodable]: The options as a list of arguments for the `XREAD` command.
264
+ """
265
+ args: List[TEncodable] = []
266
+ if self.block_ms is not None:
267
+ args.extend([self.READ_BLOCK_VALKEY_API, str(self.block_ms)])
268
+
269
+ if self.count is not None:
270
+ args.extend([self.READ_COUNT_VALKEY_API, str(self.count)])
271
+
272
+ return args
273
+
274
+
275
+ class StreamGroupOptions:
276
+ MAKE_STREAM_VALKEY_API = "MKSTREAM"
277
+ ENTRIES_READ_VALKEY_API = "ENTRIESREAD"
278
+
279
+ def __init__(self, make_stream: bool = False, entries_read: Optional[int] = None):
280
+ """
281
+ Options for creating stream consumer groups. Can be used as an optional argument to `XGROUP CREATE`.
282
+
283
+ Args:
284
+ make_stream (bool): If set to True and the stream doesn't exist, this creates a new stream with a
285
+ length of 0.
286
+ entries_read: (Optional[int]): A value representing the number of stream entries already read by the
287
+ group. This option can only be specified if you are using Valkey version 7.0.0 or above.
288
+ """
289
+ self.make_stream = make_stream
290
+ self.entries_read = entries_read
291
+
292
+ def to_args(self) -> List[TEncodable]:
293
+ """
294
+ Returns the options as a list of string arguments to be used in the `XGROUP CREATE` command.
295
+
296
+ Returns:
297
+ List[TEncodable]: The options as a list of arguments for the `XGROUP CREATE` command.
298
+ """
299
+ args: List[TEncodable] = []
300
+ if self.make_stream is True:
301
+ args.append(self.MAKE_STREAM_VALKEY_API)
302
+
303
+ if self.entries_read is not None:
304
+ args.extend([self.ENTRIES_READ_VALKEY_API, str(self.entries_read)])
305
+
306
+ return args
307
+
308
+
309
+ class StreamReadGroupOptions(StreamReadOptions):
310
+ READ_NOACK_VALKEY_API = "NOACK"
311
+
312
+ def __init__(
313
+ self, no_ack=False, block_ms: Optional[int] = None, count: Optional[int] = None
314
+ ):
315
+ """
316
+ Options for reading entries from streams using a consumer group. Can be used as an optional argument to
317
+ `XREADGROUP`.
318
+
319
+ Args:
320
+ no_ack (bool): If set, messages are not added to the Pending Entries List (PEL). This is equivalent to
321
+ acknowledging the message when it is read. Equivalent to `NOACK` in the Valkey API.
322
+ block_ms (Optional[int]): If provided, the request will be blocked for the set amount of milliseconds or
323
+ until the server has the required number of entries. Equivalent to `BLOCK` in the Valkey API.
324
+ count (Optional[int]): The maximum number of elements requested. Equivalent to `COUNT` in the Valkey API.
325
+ """
326
+ super().__init__(block_ms=block_ms, count=count)
327
+ self.no_ack = no_ack
328
+
329
+ def to_args(self) -> List[TEncodable]:
330
+ """
331
+ Returns the options as a list of string arguments to be used in the `XREADGROUP` command.
332
+
333
+ Returns:
334
+ List[TEncodable]: The options as a list of arguments for the `XREADGROUP` command.
335
+ """
336
+ args: List[TEncodable] = super().to_args()
337
+ if self.no_ack:
338
+ args.append(self.READ_NOACK_VALKEY_API)
339
+
340
+ return args
341
+
342
+
343
+ class StreamPendingOptions:
344
+ IDLE_TIME_VALKEY_API = "IDLE"
345
+
346
+ def __init__(
347
+ self,
348
+ min_idle_time_ms: Optional[int] = None,
349
+ consumer_name: Optional[TEncodable] = None,
350
+ ):
351
+ """
352
+ Options for `XPENDING` that can be used to filter returned items by minimum idle time and consumer name.
353
+
354
+ Args:
355
+ min_idle_time_ms (Optional[int]): Filters pending entries by their minimum idle time in milliseconds. This
356
+ option can only be specified if you are using Valkey version 6.2.0 or above.
357
+ consumer_name (Optional[TEncodable]): Filters pending entries by consumer name.
358
+ """
359
+ self.min_idle_time = min_idle_time_ms
360
+ self.consumer_name = consumer_name
361
+
362
+
363
+ class StreamClaimOptions:
364
+ IDLE_VALKEY_API = "IDLE"
365
+ TIME_VALKEY_API = "TIME"
366
+ RETRY_COUNT_VALKEY_API = "RETRYCOUNT"
367
+ FORCE_VALKEY_API = "FORCE"
368
+ JUST_ID_VALKEY_API = "JUSTID"
369
+
370
+ def __init__(
371
+ self,
372
+ idle: Optional[int] = None,
373
+ idle_unix_time: Optional[int] = None,
374
+ retry_count: Optional[int] = None,
375
+ is_force: Optional[bool] = False,
376
+ ):
377
+ """
378
+ Options for `XCLAIM`.
379
+
380
+ Args:
381
+ idle (Optional[int]): Set the idle time (last time it was delivered) of the message in milliseconds. If idle
382
+ is not specified, an idle of `0` is assumed, that is, the time count is reset because the message now has a
383
+ new owner trying to process it.
384
+ idle_unix_time (Optional[int]): This is the same as idle but instead of a relative amount of milliseconds,
385
+ it sets the idle time to a specific Unix time (in milliseconds). This is useful in order to rewrite the AOF
386
+ file generating `XCLAIM` commands.
387
+ retry_count (Optional[int]): Set the retry counter to the specified value. This counter is incremented every
388
+ time a message is delivered again. Normally `XCLAIM` does not alter this counter, which is just served to
389
+ clients when the `XPENDING` command is called: this way clients can detect anomalies, like messages that
390
+ are never processed for some reason after a big number of delivery attempts.
391
+ is_force (Optional[bool]): Creates the pending message entry in the PEL even if certain specified IDs are not
392
+ already in the PEL assigned to a different client. However, the message must exist in the stream, otherwise
393
+ the IDs of non-existing messages are ignored.
394
+ """
395
+ self.idle = idle
396
+ self.idle_unix_time = idle_unix_time
397
+ self.retry_count = retry_count
398
+ self.is_force = is_force
399
+
400
+ def to_args(self) -> List[TEncodable]:
401
+ """
402
+ Converts options for `XCLAIM` into a List.
403
+
404
+ Returns:
405
+ List[str]: The options as a list of arguments for the `XCLAIM` command.
406
+ """
407
+ args: List[TEncodable] = []
408
+ if self.idle:
409
+ args.append(self.IDLE_VALKEY_API)
410
+ args.append(str(self.idle))
411
+
412
+ if self.idle_unix_time:
413
+ args.append(self.TIME_VALKEY_API)
414
+ args.append(str(self.idle_unix_time))
415
+
416
+ if self.retry_count:
417
+ args.append(self.RETRY_COUNT_VALKEY_API)
418
+ args.append(str(self.retry_count))
419
+
420
+ if self.is_force:
421
+ args.append(self.FORCE_VALKEY_API)
422
+
423
+ return args
424
+
425
+
426
+ def _create_xpending_range_args(
427
+ key: TEncodable,
428
+ group_name: TEncodable,
429
+ start: StreamRangeBound,
430
+ end: StreamRangeBound,
431
+ count: int,
432
+ options: Optional[StreamPendingOptions],
433
+ ) -> List[TEncodable]:
434
+ args = [key, group_name]
435
+ if options is not None and options.min_idle_time is not None:
436
+ args.extend([options.IDLE_TIME_VALKEY_API, str(options.min_idle_time)])
437
+
438
+ args.extend([start.to_arg(), end.to_arg(), str(count)])
439
+ if options is not None and options.consumer_name is not None:
440
+ args.append(options.consumer_name)
441
+
442
+ return args