valkey-glide 2.0.1__cp311-cp311-macosx_11_0_arm64.whl → 2.1.0rc1__cp311-cp311-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.

Potentially problematic release.


This version of valkey-glide might be problematic. Click here for more details.

Files changed (43) hide show
  1. glide/__init__.py +95 -119
  2. glide/async_commands/cluster_commands.py +11 -11
  3. glide/async_commands/core.py +537 -414
  4. glide/async_commands/{server_modules/ft.py → ft.py} +8 -7
  5. glide/async_commands/{server_modules/glide_json.py → glide_json.py} +15 -92
  6. glide/async_commands/standalone_commands.py +9 -11
  7. glide/glide.cpython-311-darwin.so +0 -0
  8. glide/glide.pyi +1 -1
  9. glide/glide_client.py +39 -46
  10. glide/logger.py +3 -3
  11. glide/opentelemetry.py +8 -4
  12. glide_shared/__init__.py +326 -0
  13. {glide/async_commands → glide_shared/commands}/batch.py +396 -10
  14. {glide/async_commands → glide_shared/commands}/batch_options.py +1 -1
  15. glide_shared/commands/core_options.py +407 -0
  16. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +3 -3
  17. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +4 -2
  18. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +4 -4
  19. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +4 -2
  20. {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +4 -4
  21. glide_shared/commands/server_modules/json_options.py +93 -0
  22. {glide/async_commands → glide_shared/commands}/sorted_set.py +2 -2
  23. {glide/async_commands → glide_shared/commands}/stream.py +1 -1
  24. {glide → glide_shared}/config.py +28 -21
  25. {glide → glide_shared}/constants.py +3 -3
  26. {glide → glide_shared}/exceptions.py +27 -1
  27. glide_shared/protobuf/command_request_pb2.py +54 -0
  28. {glide → glide_shared}/routes.py +29 -15
  29. {valkey_glide-2.0.1.dist-info → valkey_glide-2.1.0rc1.dist-info}/METADATA +119 -58
  30. valkey_glide-2.1.0rc1.dist-info/RECORD +39 -0
  31. glide/protobuf/command_request_pb2.py +0 -54
  32. glide/protobuf/command_request_pb2.pyi +0 -1193
  33. glide/protobuf/connection_request_pb2.pyi +0 -299
  34. glide/protobuf/response_pb2.pyi +0 -106
  35. valkey_glide-2.0.1.dist-info/RECORD +0 -39
  36. /glide/py.typed → /glide_shared/commands/__init__.py +0 -0
  37. {glide/async_commands → glide_shared/commands}/bitmap.py +0 -0
  38. {glide/async_commands → glide_shared/commands}/command_args.py +0 -0
  39. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
  40. {glide → glide_shared}/protobuf/connection_request_pb2.py +0 -0
  41. {glide → glide_shared}/protobuf/response_pb2.py +0 -0
  42. {glide → glide_shared}/protobuf_codec.py +0 -0
  43. {valkey_glide-2.0.1.dist-info → valkey_glide-2.1.0rc1.dist-info}/WHEEL +0 -0
@@ -1,22 +1,8 @@
1
1
  # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
- from dataclasses import dataclass
3
- from datetime import datetime, timedelta
4
- from enum import Enum
5
- from typing import (
6
- Dict,
7
- List,
8
- Mapping,
9
- Optional,
10
- Protocol,
11
- Set,
12
- Tuple,
13
- Type,
14
- Union,
15
- cast,
16
- get_args,
17
- )
2
+ from typing import Dict, List, Mapping, Optional, Protocol, Set, Tuple, Union, cast
18
3
 
19
- from glide.async_commands.bitmap import (
4
+ from glide.glide import ClusterScanCursor
5
+ from glide_shared.commands.bitmap import (
20
6
  BitFieldGet,
21
7
  BitFieldSubCommands,
22
8
  BitwiseOperation,
@@ -24,8 +10,20 @@ from glide.async_commands.bitmap import (
24
10
  _create_bitfield_args,
25
11
  _create_bitfield_read_only_args,
26
12
  )
27
- from glide.async_commands.command_args import Limit, ListDirection, ObjectType, OrderBy
28
- from glide.async_commands.sorted_set import (
13
+ from glide_shared.commands.command_args import Limit, ListDirection, ObjectType, OrderBy
14
+ from glide_shared.commands.core_options import (
15
+ ConditionalChange,
16
+ ExpireOptions,
17
+ ExpiryGetEx,
18
+ ExpirySet,
19
+ HashFieldConditionalChange,
20
+ InsertPosition,
21
+ OnlyIfEqual,
22
+ PubSubMsg,
23
+ UpdateOptions,
24
+ _build_sort_args,
25
+ )
26
+ from glide_shared.commands.sorted_set import (
29
27
  AggregationType,
30
28
  GeoSearchByBox,
31
29
  GeoSearchByRadius,
@@ -43,7 +41,7 @@ from glide.async_commands.sorted_set import (
43
41
  _create_zinter_zunion_cmd_args,
44
42
  _create_zrange_args,
45
43
  )
46
- from glide.async_commands.stream import (
44
+ from glide_shared.commands.stream import (
47
45
  StreamAddOptions,
48
46
  StreamClaimOptions,
49
47
  StreamGroupOptions,
@@ -54,389 +52,16 @@ from glide.async_commands.stream import (
54
52
  StreamTrimOptions,
55
53
  _create_xpending_range_args,
56
54
  )
57
- from glide.constants import (
55
+ from glide_shared.constants import (
58
56
  TOK,
59
57
  TEncodable,
60
58
  TResult,
61
59
  TXInfoStreamFullResponse,
62
60
  TXInfoStreamResponse,
63
61
  )
64
- from glide.exceptions import RequestError
65
- from glide.protobuf.command_request_pb2 import RequestType
66
- from glide.routes import Route
67
-
68
- from ..glide import ClusterScanCursor
69
-
70
-
71
- class ConditionalChange(Enum):
72
- """
73
- A condition to the `SET`, `ZADD` and `GEOADD` commands.
74
- """
75
-
76
- ONLY_IF_EXISTS = "XX"
77
- """ Only update key / elements that already exist. Equivalent to `XX` in the Valkey API. """
78
-
79
- ONLY_IF_DOES_NOT_EXIST = "NX"
80
- """ Only set key / add elements that does not already exist. Equivalent to `NX` in the Valkey API. """
81
-
82
-
83
- @dataclass
84
- class OnlyIfEqual:
85
- """
86
- Change condition to the `SET` command,
87
- For additional conditonal options see ConditionalChange
88
-
89
- - comparison_value - value to compare to the current value of a key.
90
-
91
- If comparison_value is equal to the key, it will overwrite the value of key to the new provided value
92
- Equivalent to the IFEQ comparison-value in the Valkey API
93
- """
94
-
95
- comparison_value: TEncodable
96
-
97
-
98
- class ExpiryType(Enum):
99
- """
100
- SET option: The type of the expiry.
101
- """
102
-
103
- SEC = 0, Union[int, timedelta]
104
- """
105
- Set the specified expire time, in seconds. Equivalent to `EX` in the Valkey API.
106
- """
107
-
108
- MILLSEC = 1, Union[int, timedelta]
109
- """
110
- Set the specified expire time, in milliseconds. Equivalent to `PX` in the Valkey API.
111
- """
112
-
113
- UNIX_SEC = 2, Union[int, datetime]
114
- """
115
- Set the specified Unix time at which the key will expire, in seconds. Equivalent to `EXAT` in the Valkey API.
116
- """
117
-
118
- UNIX_MILLSEC = 3, Union[int, datetime]
119
- """
120
- Set the specified Unix time at which the key will expire, in milliseconds. Equivalent to `PXAT` in the Valkey API.
121
- """
122
-
123
- KEEP_TTL = 4, Type[None]
124
- """
125
- Retain the time to live associated with the key. Equivalent to `KEEPTTL` in the Valkey API.
126
- """
127
-
128
-
129
- class ExpiryTypeGetEx(Enum):
130
- """
131
- GetEx option: The type of the expiry.
132
- """
133
-
134
- SEC = 0, Union[int, timedelta]
135
- """ Set the specified expire time, in seconds. Equivalent to `EX` in the Valkey API. """
136
-
137
- MILLSEC = 1, Union[int, timedelta]
138
- """ Set the specified expire time, in milliseconds. Equivalent to `PX` in the Valkey API. """
139
-
140
- UNIX_SEC = 2, Union[int, datetime]
141
- """ Set the specified Unix time at which the key will expire, in seconds. Equivalent to `EXAT` in the Valkey API. """
142
-
143
- UNIX_MILLSEC = 3, Union[int, datetime]
144
- """ Set the specified Unix time at which the key will expire, in milliseconds. Equivalent to `PXAT` in the Valkey API. """
145
-
146
- PERSIST = 4, Type[None]
147
- """ Remove the time to live associated with the key. Equivalent to `PERSIST` in the Valkey API. """
148
-
149
-
150
- class InfoSection(Enum):
151
- """
152
- INFO option: a specific section of information:
153
-
154
- When no parameter is provided, the default option is assumed.
155
- """
156
-
157
- SERVER = "server"
158
- """ General information about the server """
159
-
160
- CLIENTS = "clients"
161
- """ Client connections section """
162
-
163
- MEMORY = "memory"
164
- """ Memory consumption related information """
165
-
166
- PERSISTENCE = "persistence"
167
- """ RDB and AOF related information """
168
-
169
- STATS = "stats"
170
- """ General statistics """
171
-
172
- REPLICATION = "replication"
173
- """ Master/replica replication information """
174
-
175
- CPU = "cpu"
176
- """ CPU consumption statistics """
177
-
178
- COMMAND_STATS = "commandstats"
179
- """ Valkey command statistics """
180
-
181
- LATENCY_STATS = "latencystats"
182
- """ Valkey command latency percentile distribution statistics """
183
-
184
- SENTINEL = "sentinel"
185
- """ Valkey Sentinel section (only applicable to Sentinel instances) """
186
-
187
- CLUSTER = "cluster"
188
- """ Valkey Cluster section """
189
-
190
- MODULES = "modules"
191
- """ Modules section """
192
-
193
- KEYSPACE = "keyspace"
194
- """ Database related statistics """
195
-
196
- ERROR_STATS = "errorstats"
197
- """ Valkey error statistics """
198
-
199
- ALL = "all"
200
- """ Return all sections (excluding module generated ones) """
201
-
202
- DEFAULT = "default"
203
- """ Return only the default set of sections """
204
-
205
- EVERYTHING = "everything"
206
- """ Includes all and modules """
207
-
208
-
209
- class ExpireOptions(Enum):
210
- """
211
- EXPIRE option: options for setting key expiry.
212
- """
213
-
214
- HasNoExpiry = "NX"
215
- """ Set expiry only when the key has no expiry (Equivalent to "NX" in Valkey). """
216
-
217
- HasExistingExpiry = "XX"
218
- """ Set expiry only when the key has an existing expiry (Equivalent to "XX" in Valkey). """
219
-
220
- NewExpiryGreaterThanCurrent = "GT"
221
- """
222
- Set expiry only when the new expiry is greater than the current one (Equivalent to "GT" in Valkey).
223
- """
224
-
225
- NewExpiryLessThanCurrent = "LT"
226
- """
227
- Set expiry only when the new expiry is less than the current one (Equivalent to "LT" in Valkey).
228
- """
229
-
230
-
231
- class UpdateOptions(Enum):
232
- """
233
- Options for updating elements of a sorted set key.
234
- """
235
-
236
- LESS_THAN = "LT"
237
- """ Only update existing elements if the new score is less than the current score. """
238
-
239
- GREATER_THAN = "GT"
240
- """ Only update existing elements if the new score is greater than the current score. """
241
-
242
-
243
- class ExpirySet:
244
- """
245
- SET option: Represents the expiry type and value to be executed with "SET" command.
246
-
247
- Attributes:
248
- cmd_arg (str): The expiry type.
249
- value (str): The value for the expiry type.
250
- """
251
-
252
- def __init__(
253
- self,
254
- expiry_type: ExpiryType,
255
- value: Optional[Union[int, datetime, timedelta]],
256
- ) -> None:
257
- self.set_expiry_type_and_value(expiry_type, value)
258
-
259
- def __eq__(self, other: "object") -> bool:
260
- if not isinstance(other, ExpirySet):
261
- return NotImplemented
262
- return self.expiry_type == other.expiry_type and self.value == other.value
263
-
264
- def set_expiry_type_and_value(
265
- self, expiry_type: ExpiryType, value: Optional[Union[int, datetime, timedelta]]
266
- ):
267
- """
268
- Args:
269
- expiry_type (ExpiryType): The expiry type.
270
- value (Optional[Union[int, datetime, timedelta]]): The value of the expiration type. The type of expiration
271
- determines the type of expiration value:
272
-
273
- - SEC: Union[int, timedelta]
274
- - MILLSEC: Union[int, timedelta]
275
- - UNIX_SEC: Union[int, datetime]
276
- - UNIX_MILLSEC: Union[int, datetime]
277
- - KEEP_TTL: Type[None]
278
- """
279
- if not isinstance(value, get_args(expiry_type.value[1])):
280
- raise ValueError(
281
- f"The value of {expiry_type} should be of type {expiry_type.value[1]}"
282
- )
283
- self.expiry_type = expiry_type
284
- if self.expiry_type == ExpiryType.SEC:
285
- self.cmd_arg = "EX"
286
- if isinstance(value, timedelta):
287
- value = int(value.total_seconds())
288
- elif self.expiry_type == ExpiryType.MILLSEC:
289
- self.cmd_arg = "PX"
290
- if isinstance(value, timedelta):
291
- value = int(value.total_seconds() * 1000)
292
- elif self.expiry_type == ExpiryType.UNIX_SEC:
293
- self.cmd_arg = "EXAT"
294
- if isinstance(value, datetime):
295
- value = int(value.timestamp())
296
- elif self.expiry_type == ExpiryType.UNIX_MILLSEC:
297
- self.cmd_arg = "PXAT"
298
- if isinstance(value, datetime):
299
- value = int(value.timestamp() * 1000)
300
- elif self.expiry_type == ExpiryType.KEEP_TTL:
301
- self.cmd_arg = "KEEPTTL"
302
- self.value = str(value) if value else None
303
-
304
- def get_cmd_args(self) -> List[str]:
305
- return [self.cmd_arg] if self.value is None else [self.cmd_arg, self.value]
306
-
307
-
308
- class ExpiryGetEx:
309
- """
310
- GetEx option: Represents the expiry type and value to be executed with "GetEx" command.
311
-
312
- Attributes:
313
- cmd_arg (str): The expiry type.
314
- value (str): The value for the expiry type.
315
- """
316
-
317
- def __init__(
318
- self,
319
- expiry_type: ExpiryTypeGetEx,
320
- value: Optional[Union[int, datetime, timedelta]],
321
- ) -> None:
322
- self.set_expiry_type_and_value(expiry_type, value)
323
-
324
- def set_expiry_type_and_value(
325
- self,
326
- expiry_type: ExpiryTypeGetEx,
327
- value: Optional[Union[int, datetime, timedelta]],
328
- ):
329
- """
330
- Args:
331
- expiry_type (ExpiryType): The expiry type.
332
- value (Optional[Union[int, datetime, timedelta]]): The value of the expiration type. The type of expiration
333
- determines the type of expiration value:
334
-
335
- - SEC: Union[int, timedelta]
336
- - MILLSEC: Union[int, timedelta]
337
- - UNIX_SEC: Union[int, datetime]
338
- - UNIX_MILLSEC: Union[int, datetime]
339
- - PERSIST: Type[None]
340
- """
341
- if not isinstance(value, get_args(expiry_type.value[1])):
342
- raise ValueError(
343
- f"The value of {expiry_type} should be of type {expiry_type.value[1]}"
344
- )
345
- self.expiry_type = expiry_type
346
- if self.expiry_type == ExpiryTypeGetEx.SEC:
347
- self.cmd_arg = "EX"
348
- if isinstance(value, timedelta):
349
- value = int(value.total_seconds())
350
- elif self.expiry_type == ExpiryTypeGetEx.MILLSEC:
351
- self.cmd_arg = "PX"
352
- if isinstance(value, timedelta):
353
- value = int(value.total_seconds() * 1000)
354
- elif self.expiry_type == ExpiryTypeGetEx.UNIX_SEC:
355
- self.cmd_arg = "EXAT"
356
- if isinstance(value, datetime):
357
- value = int(value.timestamp())
358
- elif self.expiry_type == ExpiryTypeGetEx.UNIX_MILLSEC:
359
- self.cmd_arg = "PXAT"
360
- if isinstance(value, datetime):
361
- value = int(value.timestamp() * 1000)
362
- elif self.expiry_type == ExpiryTypeGetEx.PERSIST:
363
- self.cmd_arg = "PERSIST"
364
- self.value = str(value) if value else None
365
-
366
- def get_cmd_args(self) -> List[str]:
367
- return [self.cmd_arg] if self.value is None else [self.cmd_arg, self.value]
368
-
369
-
370
- class InsertPosition(Enum):
371
- BEFORE = "BEFORE"
372
- AFTER = "AFTER"
373
-
374
-
375
- class FlushMode(Enum):
376
- """
377
- Defines flushing mode for:
378
-
379
- `FLUSHALL` command and `FUNCTION FLUSH` command.
380
-
381
- See [FLUSHAL](https://valkey.io/commands/flushall/) and [FUNCTION-FLUSH](https://valkey.io/commands/function-flush/)
382
- for details
383
-
384
- SYNC was introduced in version 6.2.0.
385
- """
386
-
387
- ASYNC = "ASYNC"
388
- SYNC = "SYNC"
389
-
390
-
391
- class FunctionRestorePolicy(Enum):
392
- """
393
- Options for the FUNCTION RESTORE command.
394
- """
395
-
396
- APPEND = "APPEND"
397
- """ Appends the restored libraries to the existing libraries and aborts on collision. This is the default policy. """
398
-
399
- FLUSH = "FLUSH"
400
- """ Deletes all existing libraries before restoring the payload. """
401
-
402
- REPLACE = "REPLACE"
403
- """
404
- Appends the restored libraries to the existing libraries, replacing any existing ones in case
405
- of name collisions. Note that this policy doesn't prevent function name collisions, only libraries.
406
- """
407
-
408
-
409
- def _build_sort_args(
410
- key: TEncodable,
411
- by_pattern: Optional[TEncodable] = None,
412
- limit: Optional[Limit] = None,
413
- get_patterns: Optional[List[TEncodable]] = None,
414
- order: Optional[OrderBy] = None,
415
- alpha: Optional[bool] = None,
416
- store: Optional[TEncodable] = None,
417
- ) -> List[TEncodable]:
418
- args = [key]
419
-
420
- if by_pattern:
421
- args.extend(["BY", by_pattern])
422
-
423
- if limit:
424
- args.extend(["LIMIT", str(limit.offset), str(limit.count)])
425
-
426
- if get_patterns:
427
- for pattern in get_patterns:
428
- args.extend(["GET", pattern])
429
-
430
- if order:
431
- args.append(order.value)
432
-
433
- if alpha:
434
- args.append("ALPHA")
435
-
436
- if store:
437
- args.extend(["STORE", store])
438
-
439
- return args
62
+ from glide_shared.exceptions import RequestError
63
+ from glide_shared.protobuf.command_request_pb2 import RequestType
64
+ from glide_shared.routes import Route
440
65
 
441
66
 
442
67
  class CoreCommands(Protocol):
@@ -1478,6 +1103,519 @@ class CoreCommands(Protocol):
1478
1103
  await self._execute_command(RequestType.HStrlen, [key, field]),
1479
1104
  )
1480
1105
 
1106
+ async def httl(self, key: TEncodable, fields: List[TEncodable]) -> List[int]:
1107
+ """
1108
+ Returns the remaining time to live (in seconds) of hash key's field(s) that have an associated expiration.
1109
+
1110
+ See [valkey.io](https://valkey.io/commands/httl/) for more details.
1111
+
1112
+ Args:
1113
+ key (TEncodable): The key of the hash.
1114
+ fields (List[TEncodable]): The list of fields to get TTL for.
1115
+
1116
+ Returns:
1117
+ List[int]: A list of TTL values for each field:
1118
+ - Positive integer: remaining TTL in seconds
1119
+ - `-1`: field exists but has no expiration
1120
+ - `-2`: field does not exist or key does not exist
1121
+
1122
+ Examples:
1123
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.EX, 10))
1124
+ >>> await client.httl("my_hash", ["field1", "field2", "non_existent_field"])
1125
+ [9, 9, -2] # field1 and field2 have ~9 seconds left, non_existent_field doesn't exist
1126
+
1127
+ Since: Valkey 9.0.0
1128
+ """
1129
+ return cast(
1130
+ List[int],
1131
+ await self._execute_command(
1132
+ RequestType.HTtl, [key, "FIELDS", str(len(fields))] + fields
1133
+ ),
1134
+ )
1135
+
1136
+ async def hpttl(self, key: TEncodable, fields: List[TEncodable]) -> List[int]:
1137
+ """
1138
+ Returns the remaining time to live (in milliseconds) of hash key's field(s) that have an associated expiration.
1139
+
1140
+ See [valkey.io](https://valkey.io/commands/hpttl/) for more details.
1141
+
1142
+ Args:
1143
+ key (TEncodable): The key of the hash.
1144
+ fields (List[TEncodable]): The list of fields to get TTL for.
1145
+
1146
+ Returns:
1147
+ List[int]: A list of TTL values for each field:
1148
+ - Positive integer: remaining TTL in milliseconds
1149
+ - `-1`: field exists but has no expiration
1150
+ - `-2`: field does not exist or key does not exist
1151
+
1152
+ Examples:
1153
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.PX, 10000))
1154
+ >>> await client.hpttl("my_hash", ["field1", "field2", "non_existent_field"])
1155
+ [9500, 9500, -2] # field1 and field2 have ~9500 milliseconds left, non_existent_field doesn't exist
1156
+
1157
+ Since: Valkey 9.0.0
1158
+ """
1159
+ return cast(
1160
+ List[int],
1161
+ await self._execute_command(
1162
+ RequestType.HPTtl, [key, "FIELDS", str(len(fields))] + fields
1163
+ ),
1164
+ )
1165
+
1166
+ async def hexpiretime(self, key: TEncodable, fields: List[TEncodable]) -> List[int]:
1167
+ """
1168
+ Returns the expiration Unix timestamp (in seconds) of hash key's field(s) that have an associated expiration.
1169
+
1170
+ See [valkey.io](https://valkey.io/commands/hexpiretime/) for more details.
1171
+
1172
+ Args:
1173
+ key (TEncodable): The key of the hash.
1174
+ fields (List[TEncodable]): The list of fields to get expiration timestamps for.
1175
+
1176
+ Returns:
1177
+ List[int]: A list of expiration timestamps for each field:
1178
+ - Positive integer: absolute expiration timestamp in seconds (Unix timestamp)
1179
+ - `-1`: field exists but has no expiration
1180
+ - `-2`: field does not exist or key does not exist
1181
+
1182
+ Examples:
1183
+ >>> import time
1184
+ >>> future_timestamp = int(time.time()) + 60 # 60 seconds from now
1185
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.EXAT, future_timestamp))
1186
+ >>> await client.hexpiretime("my_hash", ["field1", "field2", "non_existent_field"])
1187
+ [future_timestamp, future_timestamp, -2] # field1 and field2 expire at future_timestamp, non_existent_field doesn't exist
1188
+
1189
+ Since: Valkey 9.0.0
1190
+ """
1191
+ return cast(
1192
+ List[int],
1193
+ await self._execute_command(
1194
+ RequestType.HExpireTime, [key, "FIELDS", str(len(fields))] + fields
1195
+ ),
1196
+ )
1197
+
1198
+ async def hpexpiretime(
1199
+ self, key: TEncodable, fields: List[TEncodable]
1200
+ ) -> List[int]:
1201
+ """
1202
+ Returns the expiration Unix timestamp (in milliseconds) of hash key's field(s) that have an associated expiration.
1203
+
1204
+ See [valkey.io](https://valkey.io/commands/hpexpiretime/) for more details.
1205
+
1206
+ Args:
1207
+ key (TEncodable): The key of the hash.
1208
+ fields (List[TEncodable]): The list of fields to get expiration timestamps for.
1209
+
1210
+ Returns:
1211
+ List[int]: A list of expiration timestamps for each field:
1212
+ - Positive integer: absolute expiration timestamp in milliseconds (Unix timestamp in ms)
1213
+ - `-1`: field exists but has no expiration
1214
+ - `-2`: field does not exist or key does not exist
1215
+
1216
+ Examples:
1217
+ >>> import time
1218
+ >>> future_timestamp_ms = int(time.time() * 1000) + 60000 # 60 seconds from now in milliseconds
1219
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.PXAT, future_timestamp_ms))
1220
+ >>> await client.hpexpiretime("my_hash", ["field1", "field2", "non_existent_field"])
1221
+ [future_timestamp_ms, future_timestamp_ms, -2] # field1 and field2 expire at future_timestamp_ms, non_existent_field doesn't exist
1222
+
1223
+ Since: Valkey 9.0.0
1224
+ """
1225
+ return cast(
1226
+ List[int],
1227
+ await self._execute_command(
1228
+ RequestType.HPExpireTime, [key, "FIELDS", str(len(fields))] + fields
1229
+ ),
1230
+ )
1231
+
1232
+ async def hsetex(
1233
+ self,
1234
+ key: TEncodable,
1235
+ field_value_map: Mapping[TEncodable, TEncodable],
1236
+ field_conditional_change: Optional[HashFieldConditionalChange] = None,
1237
+ expiry: Optional[ExpirySet] = None,
1238
+ ) -> int:
1239
+ """
1240
+ Sets the specified fields to their respective values in the hash stored at `key` with optional expiration.
1241
+
1242
+ See [valkey.io](https://valkey.io/commands/hsetex/) for more details.
1243
+
1244
+ Args:
1245
+ key (TEncodable): The key of the hash.
1246
+ field_value_map (Mapping[TEncodable, TEncodable]): A field-value map consisting of fields and their corresponding
1247
+ values to be set in the hash stored at the specified key.
1248
+ field_conditional_change (Optional[HashFieldConditionalChange]): Field conditional change option:
1249
+ - ONLY_IF_ALL_EXIST (FXX): Only set fields if all of them already exist.
1250
+ - ONLY_IF_NONE_EXIST (FNX): Only set fields if none of them already exist.
1251
+ expiry (Optional[ExpirySet]): Expiration options for the fields:
1252
+ - EX: Expiration time in seconds.
1253
+ - PX: Expiration time in milliseconds.
1254
+ - EXAT: Absolute expiration time in seconds (Unix timestamp).
1255
+ - PXAT: Absolute expiration time in milliseconds (Unix timestamp).
1256
+ - KEEPTTL: Retain existing TTL.
1257
+
1258
+ Returns:
1259
+ int: 1 if all fields were set successfully, 0 if none were set due to conditional constraints.
1260
+
1261
+ Examples:
1262
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.EX, 10))
1263
+ 1 # All fields set with 10 second expiration
1264
+ >>> await client.hsetex("my_hash", {"field3": "value3"}, field_conditional_change=HashFieldConditionalChange.ONLY_IF_ALL_EXIST)
1265
+ 1 # Field set because field already exists
1266
+ >>> await client.hsetex("new_hash", {"field1": "value1"}, field_conditional_change=HashFieldConditionalChange.ONLY_IF_ALL_EXIST)
1267
+ 0 # No fields set because hash doesn't exist
1268
+
1269
+ Since: Valkey 9.0.0
1270
+ """
1271
+ args: List[TEncodable] = [key]
1272
+
1273
+ # Add field conditional change option if specified
1274
+ if field_conditional_change is not None:
1275
+ args.append(field_conditional_change.value)
1276
+
1277
+ # Add expiry options if specified
1278
+ if expiry is not None:
1279
+ args.extend(expiry.get_cmd_args())
1280
+
1281
+ # Add FIELDS keyword and field count
1282
+ args.extend(["FIELDS", str(len(field_value_map))])
1283
+
1284
+ # Add field-value pairs
1285
+ for field, value in field_value_map.items():
1286
+ args.extend([field, value])
1287
+
1288
+ return cast(
1289
+ int,
1290
+ await self._execute_command(RequestType.HSetEx, args),
1291
+ )
1292
+
1293
+ async def hgetex(
1294
+ self,
1295
+ key: TEncodable,
1296
+ fields: List[TEncodable],
1297
+ expiry: Optional[ExpiryGetEx] = None,
1298
+ ) -> Optional[List[Optional[bytes]]]:
1299
+ """
1300
+ Retrieves the values of specified fields in the hash stored at `key` and optionally sets their expiration.
1301
+
1302
+ See [valkey.io](https://valkey.io/commands/hgetex/) for more details.
1303
+
1304
+ Args:
1305
+ key (TEncodable): The key of the hash.
1306
+ fields (List[TEncodable]): The list of fields to retrieve from the hash.
1307
+ expiry (Optional[ExpiryGetEx]): Expiration options for the retrieved fields:
1308
+ - EX: Expiration time in seconds.
1309
+ - PX: Expiration time in milliseconds.
1310
+ - EXAT: Absolute expiration time in seconds (Unix timestamp).
1311
+ - PXAT: Absolute expiration time in milliseconds (Unix timestamp).
1312
+ - PERSIST: Remove expiration from the fields.
1313
+
1314
+ Returns:
1315
+ Optional[List[Optional[bytes]]]: A list of values associated with the given fields, in the same order as requested.
1316
+ For every field that does not exist in the hash, a null value is returned.
1317
+ If `key` does not exist, it is treated as an empty hash, and the function returns a list of null values.
1318
+
1319
+ Examples:
1320
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.EX, 10))
1321
+ >>> await client.hgetex("my_hash", ["field1", "field2"])
1322
+ [b"value1", b"value2"]
1323
+ >>> await client.hgetex("my_hash", ["field1"], expiry=ExpiryGetEx(ExpiryTypeGetEx.EX, 20))
1324
+ [b"value1"] # field1 now has 20 second expiration
1325
+ >>> await client.hgetex("my_hash", ["field1"], expiry=ExpiryGetEx(ExpiryTypeGetEx.PERSIST, None))
1326
+ [b"value1"] # field1 expiration removed
1327
+
1328
+ Since: Valkey 9.0.0
1329
+ """
1330
+ args: List[TEncodable] = [key]
1331
+
1332
+ # Add expiry options if specified
1333
+ if expiry is not None:
1334
+ args.extend(expiry.get_cmd_args())
1335
+
1336
+ # Add FIELDS keyword and field count
1337
+ args.extend(["FIELDS", str(len(fields))])
1338
+
1339
+ # Add fields
1340
+ args.extend(fields)
1341
+
1342
+ return cast(
1343
+ Optional[List[Optional[bytes]]],
1344
+ await self._execute_command(RequestType.HGetEx, args),
1345
+ )
1346
+
1347
+ async def hexpire(
1348
+ self,
1349
+ key: TEncodable,
1350
+ seconds: int,
1351
+ fields: List[TEncodable],
1352
+ option: Optional[ExpireOptions] = None,
1353
+ ) -> List[int]:
1354
+ """
1355
+ Sets expiration time in seconds for one or more hash fields.
1356
+
1357
+ See [valkey.io](https://valkey.io/commands/hexpire/) for more details.
1358
+
1359
+ Args:
1360
+ key (TEncodable): The key of the hash.
1361
+ seconds (int): The expiration time in seconds.
1362
+ fields (List[TEncodable]): The list of fields to set expiration for.
1363
+ option (Optional[ExpireOptions]): Conditional expiration option:
1364
+ - HasNoExpiry (NX): Set expiration only when the field has no expiry.
1365
+ - HasExistingExpiry (XX): Set expiration only when the field has an existing expiry.
1366
+ - NewExpiryGreaterThanCurrent (GT): Set expiration only when the new expiry is greater than the current one.
1367
+ - NewExpiryLessThanCurrent (LT): Set expiration only when the new expiry is less than the current one.
1368
+
1369
+ Returns:
1370
+ List[int]: A list of status codes for each field:
1371
+ - `1`: Expiration time was applied successfully.
1372
+ - `0`: Specified condition was not met.
1373
+ - `-2`: Field does not exist or key does not exist.
1374
+ - `2`: Field was deleted immediately (when seconds is 0 or timestamp is in the past).
1375
+
1376
+ Examples:
1377
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.EX, 10))
1378
+ >>> await client.hexpire("my_hash", 20, ["field1", "field2"])
1379
+ [1, 1] # Both fields' expiration set to 20 seconds
1380
+ >>> await client.hexpire("my_hash", 30, ["field1"], option=ExpireOptions.NewExpiryGreaterThanCurrent)
1381
+ [1] # field1 expiration updated to 30 seconds (greater than current 20)
1382
+ >>> await client.hexpire("my_hash", 0, ["field2"])
1383
+ [2] # field2 deleted immediately
1384
+ >>> await client.hexpire("my_hash", 10, ["non_existent_field"])
1385
+ [-2] # Field doesn't exist
1386
+
1387
+ Since: Valkey 9.0.0
1388
+ """
1389
+ args: List[TEncodable] = [key, str(seconds)]
1390
+
1391
+ # Add conditional option if specified
1392
+ if option is not None:
1393
+ args.append(option.value)
1394
+
1395
+ # Add FIELDS keyword and field count
1396
+ args.extend(["FIELDS", str(len(fields))])
1397
+
1398
+ # Add fields
1399
+ args.extend(fields)
1400
+
1401
+ return cast(
1402
+ List[int],
1403
+ await self._execute_command(RequestType.HExpire, args),
1404
+ )
1405
+
1406
+ async def hpersist(self, key: TEncodable, fields: List[TEncodable]) -> List[int]:
1407
+ """
1408
+ Removes the expiration from one or more hash fields, making them persistent.
1409
+
1410
+ See [valkey.io](https://valkey.io/commands/hpersist/) for more details.
1411
+
1412
+ Args:
1413
+ key (TEncodable): The key of the hash.
1414
+ fields (List[TEncodable]): The list of fields to remove expiration from.
1415
+
1416
+ Returns:
1417
+ List[int]: A list of status codes for each field:
1418
+ - `1`: Expiration was removed successfully (field became persistent).
1419
+ - `-1`: Field exists but has no expiration.
1420
+ - `-2`: Field does not exist or key does not exist.
1421
+
1422
+ Examples:
1423
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.EX, 10))
1424
+ >>> await client.hpersist("my_hash", ["field1", "field2"])
1425
+ [1, 1] # Both fields made persistent
1426
+ >>> await client.hpersist("my_hash", ["field1"])
1427
+ [-1] # field1 already persistent
1428
+ >>> await client.hpersist("my_hash", ["non_existent_field"])
1429
+ [-2] # Field doesn't exist
1430
+
1431
+ Since: Valkey 9.0.0
1432
+ """
1433
+ args: List[TEncodable] = [key, "FIELDS", str(len(fields))] + fields
1434
+
1435
+ return cast(
1436
+ List[int],
1437
+ await self._execute_command(RequestType.HPersist, args),
1438
+ )
1439
+
1440
+ async def hpexpire(
1441
+ self,
1442
+ key: TEncodable,
1443
+ milliseconds: int,
1444
+ fields: List[TEncodable],
1445
+ option: Optional[ExpireOptions] = None,
1446
+ ) -> List[int]:
1447
+ """
1448
+ Sets expiration time in milliseconds for one or more hash fields.
1449
+
1450
+ See [valkey.io](https://valkey.io/commands/hpexpire/) for more details.
1451
+
1452
+ Args:
1453
+ key (TEncodable): The key of the hash.
1454
+ milliseconds (int): The expiration time in milliseconds.
1455
+ fields (List[TEncodable]): The list of fields to set expiration for.
1456
+ option (Optional[ExpireOptions]): Conditional expiration option:
1457
+ - HasNoExpiry (NX): Set expiration only when the field has no expiry.
1458
+ - HasExistingExpiry (XX): Set expiration only when the field has an existing expiry.
1459
+ - NewExpiryGreaterThanCurrent (GT): Set expiration only when the new expiry is greater than the current one.
1460
+ - NewExpiryLessThanCurrent (LT): Set expiration only when the new expiry is less than the current one.
1461
+
1462
+ Returns:
1463
+ List[int]: A list of status codes for each field:
1464
+ - `1`: Expiration time was applied successfully.
1465
+ - `0`: Specified condition was not met.
1466
+ - `-2`: Field does not exist or key does not exist.
1467
+ - `2`: Field was deleted immediately (when milliseconds is 0 or timestamp is in the past).
1468
+
1469
+ Examples:
1470
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.PX, 10000))
1471
+ >>> await client.hpexpire("my_hash", 20000, ["field1", "field2"])
1472
+ [1, 1] # Both fields' expiration set to 20000 milliseconds
1473
+ >>> await client.hpexpire("my_hash", 30000, ["field1"], option=ExpireOptions.NewExpiryGreaterThanCurrent)
1474
+ [1] # field1 expiration updated to 30000 milliseconds (greater than current 20000)
1475
+ >>> await client.hpexpire("my_hash", 0, ["field2"])
1476
+ [2] # field2 deleted immediately
1477
+ >>> await client.hpexpire("my_hash", 10000, ["non_existent_field"])
1478
+ [-2] # Field doesn't exist
1479
+
1480
+ Since: Valkey 9.0.0
1481
+ """
1482
+ args: List[TEncodable] = [key, str(milliseconds)]
1483
+
1484
+ # Add conditional option if specified
1485
+ if option is not None:
1486
+ args.append(option.value)
1487
+
1488
+ # Add FIELDS keyword and field count
1489
+ args.extend(["FIELDS", str(len(fields))])
1490
+
1491
+ # Add fields
1492
+ args.extend(fields)
1493
+
1494
+ return cast(
1495
+ List[int],
1496
+ await self._execute_command(RequestType.HPExpire, args),
1497
+ )
1498
+
1499
+ async def hexpireat(
1500
+ self,
1501
+ key: TEncodable,
1502
+ unix_timestamp: int,
1503
+ fields: List[TEncodable],
1504
+ option: Optional[ExpireOptions] = None,
1505
+ ) -> List[int]:
1506
+ """
1507
+ Sets expiration time at absolute Unix timestamp in seconds for one or more hash fields.
1508
+
1509
+ See [valkey.io](https://valkey.io/commands/hexpireat/) for more details.
1510
+
1511
+ Args:
1512
+ key (TEncodable): The key of the hash.
1513
+ unix_timestamp (int): The absolute expiration time as Unix timestamp in seconds.
1514
+ fields (List[TEncodable]): The list of fields to set expiration for.
1515
+ option (Optional[ExpireOptions]): Conditional expiration option:
1516
+ - HasNoExpiry (NX): Set expiration only when the field has no expiry.
1517
+ - HasExistingExpiry (XX): Set expiration only when the field has an existing expiry.
1518
+ - NewExpiryGreaterThanCurrent (GT): Set expiration only when the new expiry is greater than the current one.
1519
+ - NewExpiryLessThanCurrent (LT): Set expiration only when the new expiry is less than the current one.
1520
+
1521
+ Returns:
1522
+ List[int]: A list of status codes for each field:
1523
+ - `1`: Expiration time was applied successfully.
1524
+ - `0`: Specified condition was not met.
1525
+ - `-2`: Field does not exist or key does not exist.
1526
+ - `2`: Field was deleted immediately (when timestamp is in the past).
1527
+
1528
+ Examples:
1529
+ >>> import time
1530
+ >>> future_timestamp = int(time.time()) + 60 # 60 seconds from now
1531
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.EX, 10))
1532
+ >>> await client.hexpireat("my_hash", future_timestamp, ["field1", "field2"])
1533
+ [1, 1] # Both fields' expiration set to future_timestamp
1534
+ >>> past_timestamp = int(time.time()) - 60 # 60 seconds ago
1535
+ >>> await client.hexpireat("my_hash", past_timestamp, ["field1"])
1536
+ [2] # field1 deleted immediately (past timestamp)
1537
+ >>> await client.hexpireat("my_hash", future_timestamp, ["non_existent_field"])
1538
+ [-2] # Field doesn't exist
1539
+
1540
+ Since: Valkey 9.0.0
1541
+ """
1542
+ args: List[TEncodable] = [key, str(unix_timestamp)]
1543
+
1544
+ # Add conditional option if specified
1545
+ if option is not None:
1546
+ args.append(option.value)
1547
+
1548
+ # Add FIELDS keyword and field count
1549
+ args.extend(["FIELDS", str(len(fields))])
1550
+
1551
+ # Add fields
1552
+ args.extend(fields)
1553
+
1554
+ return cast(
1555
+ List[int],
1556
+ await self._execute_command(RequestType.HExpireAt, args),
1557
+ )
1558
+
1559
+ async def hpexpireat(
1560
+ self,
1561
+ key: TEncodable,
1562
+ unix_timestamp_ms: int,
1563
+ fields: List[TEncodable],
1564
+ option: Optional[ExpireOptions] = None,
1565
+ ) -> List[int]:
1566
+ """
1567
+ Sets expiration time at absolute Unix timestamp in milliseconds for one or more hash fields.
1568
+
1569
+ See [valkey.io](https://valkey.io/commands/hpexpireat/) for more details.
1570
+
1571
+ Args:
1572
+ key (TEncodable): The key of the hash.
1573
+ unix_timestamp_ms (int): The absolute expiration time as Unix timestamp in milliseconds.
1574
+ fields (List[TEncodable]): The list of fields to set expiration for.
1575
+ option (Optional[ExpireOptions]): Conditional expiration option:
1576
+ - HasNoExpiry (NX): Set expiration only when the field has no expiry.
1577
+ - HasExistingExpiry (XX): Set expiration only when the field has an existing expiry.
1578
+ - NewExpiryGreaterThanCurrent (GT): Set expiration only when the new expiry is greater than the current one.
1579
+ - NewExpiryLessThanCurrent (LT): Set expiration only when the new expiry is less than the current one.
1580
+
1581
+ Returns:
1582
+ List[int]: A list of status codes for each field:
1583
+ - `1`: Expiration time was applied successfully.
1584
+ - `0`: Specified condition was not met.
1585
+ - `-2`: Field does not exist or key does not exist.
1586
+ - `2`: Field was deleted immediately (when timestamp is in the past).
1587
+
1588
+ Examples:
1589
+ >>> import time
1590
+ >>> future_timestamp_ms = int(time.time() * 1000) + 60000 # 60 seconds from now in milliseconds
1591
+ >>> await client.hsetex("my_hash", {"field1": "value1", "field2": "value2"}, expiry=ExpirySet(ExpiryType.PX, 10000))
1592
+ >>> await client.hpexpireat("my_hash", future_timestamp_ms, ["field1", "field2"])
1593
+ [1, 1] # Both fields' expiration set to future_timestamp_ms
1594
+ >>> past_timestamp_ms = int(time.time() * 1000) - 60000 # 60 seconds ago in milliseconds
1595
+ >>> await client.hpexpireat("my_hash", past_timestamp_ms, ["field1"])
1596
+ [2] # field1 deleted immediately (past timestamp)
1597
+ >>> await client.hpexpireat("my_hash", future_timestamp_ms, ["non_existent_field"])
1598
+ [-2] # Field doesn't exist
1599
+
1600
+ Since: Valkey 9.0.0
1601
+ """
1602
+ args: List[TEncodable] = [key, str(unix_timestamp_ms)]
1603
+
1604
+ # Add conditional option if specified
1605
+ if option is not None:
1606
+ args.append(option.value)
1607
+
1608
+ # Add FIELDS keyword and field count
1609
+ args.extend(["FIELDS", str(len(fields))])
1610
+
1611
+ # Add fields
1612
+ args.extend(fields)
1613
+
1614
+ return cast(
1615
+ List[int],
1616
+ await self._execute_command(RequestType.HPExpireAt, args),
1617
+ )
1618
+
1481
1619
  async def lpush(self, key: TEncodable, elements: List[TEncodable]) -> int:
1482
1620
  """
1483
1621
  Insert all the specified values at the head of the list stored at `key`.
@@ -6994,7 +7132,7 @@ class CoreCommands(Protocol):
6994
7132
  See [valkey.io](https://valkey.io/commands/watch) for more details.
6995
7133
 
6996
7134
  Note:
6997
- In cluster mode, if keys in `key_value_map` map to different hash slots,
7135
+ In cluster mode, if keys in `keys` map to different hash slots,
6998
7136
  the command will be split across these slots and executed separately for each.
6999
7137
  This means the command is atomic only at the slot level. If one or more slot-specific
7000
7138
  requests fail, the entire call will return the first encountered error, even
@@ -7013,7 +7151,7 @@ class CoreCommands(Protocol):
7013
7151
  'OK'
7014
7152
  >>> transaction.set("sampleKey", "foobar")
7015
7153
  >>> await client.exec(transaction)
7016
- 'OK' # Executes successfully and keys are unwatched.
7154
+ ['OK'] # Executes successfully and keys are unwatched.
7017
7155
 
7018
7156
  >>> await client.watch("sampleKey")
7019
7157
  'OK'
@@ -7029,21 +7167,6 @@ class CoreCommands(Protocol):
7029
7167
  await self._execute_command(RequestType.Watch, keys),
7030
7168
  )
7031
7169
 
7032
- @dataclass
7033
- class PubSubMsg:
7034
- """
7035
- Describes the incoming pubsub message
7036
-
7037
- Attributes:
7038
- message (TEncodable): Incoming message.
7039
- channel (TEncodable): Name of an channel that triggered the message.
7040
- pattern (Optional[TEncodable]): Pattern that triggered the message.
7041
- """
7042
-
7043
- message: TEncodable
7044
- channel: TEncodable
7045
- pattern: Optional[TEncodable]
7046
-
7047
7170
  async def get_pubsub_message(self) -> PubSubMsg:
7048
7171
  """
7049
7172
  Returns the next pubsub message.