valkey-glide 1.3.5__cp39-cp39-macosx_11_0_arm64.whl → 2.2.2__cp39-cp39-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 (47) hide show
  1. glide/__init__.py +165 -107
  2. glide/async_commands/cluster_commands.py +318 -136
  3. glide/async_commands/core.py +1770 -992
  4. glide/async_commands/{server_modules/ft.py → ft.py} +91 -21
  5. glide/async_commands/{server_modules/glide_json.py → glide_json.py} +148 -134
  6. glide/async_commands/standalone_commands.py +203 -137
  7. glide/glide.cpython-39-darwin.so +0 -0
  8. glide/glide.pyi +26 -1
  9. glide/glide_client.py +352 -135
  10. glide/logger.py +34 -22
  11. glide/opentelemetry.py +185 -0
  12. glide_shared/__init__.py +330 -0
  13. glide_shared/commands/__init__.py +0 -0
  14. glide/async_commands/transaction.py → glide_shared/commands/batch.py +1839 -1017
  15. glide_shared/commands/batch_options.py +261 -0
  16. {glide/async_commands → glide_shared/commands}/bitmap.py +94 -85
  17. {glide/async_commands → glide_shared/commands}/command_args.py +7 -6
  18. glide_shared/commands/core_options.py +407 -0
  19. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +18 -11
  20. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +27 -13
  21. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +16 -11
  22. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +16 -8
  23. {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +160 -130
  24. glide_shared/commands/server_modules/json_options.py +93 -0
  25. {glide/async_commands → glide_shared/commands}/sorted_set.py +41 -31
  26. {glide/async_commands → glide_shared/commands}/stream.py +95 -88
  27. glide_shared/config.py +975 -0
  28. {glide → glide_shared}/constants.py +11 -7
  29. {glide → glide_shared}/exceptions.py +27 -1
  30. glide_shared/protobuf/command_request_pb2.py +56 -0
  31. glide_shared/protobuf/connection_request_pb2.py +56 -0
  32. {glide → glide_shared}/protobuf/response_pb2.py +6 -6
  33. {glide → glide_shared}/protobuf_codec.py +7 -6
  34. glide_shared/routes.py +161 -0
  35. valkey_glide-2.2.2.dist-info/METADATA +211 -0
  36. valkey_glide-2.2.2.dist-info/RECORD +40 -0
  37. glide/config.py +0 -590
  38. glide/protobuf/command_request_pb2.py +0 -54
  39. glide/protobuf/command_request_pb2.pyi +0 -1164
  40. glide/protobuf/connection_request_pb2.py +0 -52
  41. glide/protobuf/connection_request_pb2.pyi +0 -292
  42. glide/protobuf/response_pb2.pyi +0 -101
  43. glide/routes.py +0 -114
  44. valkey_glide-1.3.5.dist-info/METADATA +0 -125
  45. valkey_glide-1.3.5.dist-info/RECORD +0 -37
  46. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
  47. {valkey_glide-1.3.5.dist-info → valkey_glide-2.2.2.dist-info}/WHEEL +0 -0
@@ -0,0 +1,40 @@
1
+ valkey_glide-2.2.2.dist-info/METADATA,sha256=zR9n1QhTaaxGQkMDmfXw3oOuisaXJbFx8I0UHB3ETGY,6998
2
+ valkey_glide-2.2.2.dist-info/WHEEL,sha256=SjFvs0za84r93yXv_seM90QIJLVMin7Qs7nbzy5Blh4,104
3
+ glide/async_commands/glide_json.py,sha256=H5dnB4vJkGPpNXJZhhVyPQoTSbkN_chq5Xw6tkP0wMQ,60410
4
+ glide/async_commands/ft.py,sha256=1v96sBCgiXtPbj85ZurY3ruLCmok3cPoaIXSiJBEv9Y,16849
5
+ glide/async_commands/__init__.py,sha256=_tbTAFATlzp4L2qe-H77PpAQK-16VsV-y7uKNUKLC_o,136
6
+ glide/async_commands/core.py,sha256=x6lu7xt_pLR5drYDzNHTj0ORYX_oL73v2ZN4yxrTxGk,330289
7
+ glide/async_commands/standalone_commands.py,sha256=0YgOnH-8VVM8Cz_iJ2YxTeh8BdLpaxCjROkDhe_2Om8,38228
8
+ glide/async_commands/cluster_commands.py,sha256=NbRijIA22tDaBZg3VlBPUBGmgZ5elq5KnW-FEha9tfI,61045
9
+ glide/__init__.py,sha256=u_9M1dUNtZcI8AwbgnA_8Aox81Xbv_oLvn2ApSOmHCY,8843
10
+ glide/glide.pyi,sha256=6JIpAeADQ-1fU1Mp99pyh7aJORDxAAdtQebV5aByIVI,2093
11
+ glide/opentelemetry.py,sha256=vg9fTYXj7_rni7hVBkZBJ1ZN4-RSGde5fOH4DsnVx_4,7476
12
+ glide/glide_client.py,sha256=dyfHPiDTjvvCcOEcR2HyHK95-9WfYflXXAcLfyetfMk,32981
13
+ glide/logger.py,sha256=5-bAhfH_6hYEXdcgBR9R_wdeffSLHqEN-aQeIyMHnYY,4103
14
+ glide/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ glide_shared/__init__.py,sha256=CWiz6vdOysZ-J8skev8VIXG2SPdNaJ8lk-5emGAzzE4,7217
16
+ glide_shared/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ glide_shared/commands/batch.py,sha256=CYf12G6vQhUv2CcziwQJ5ZTE2c2DDvKEBlx2sgmi-K0,247356
18
+ glide_shared/commands/batch_options.py,sha256=i2lDCLhMzUvpArb2bxX16xu7X-im0hLPaLXALkxWeQ8,11130
19
+ glide_shared/commands/bitmap.py,sha256=ZHGLcKBP7RADtANqIR7PWdIW_gfDBFgpkIsQ-T4QFBQ,10125
20
+ glide_shared/commands/command_args.py,sha256=55vpSxeQr8wFU7olkFTEecl66wPk1g6vWxVYj16UvXs,2529
21
+ glide_shared/commands/core_options.py,sha256=Y_1dFbW50hIHl16xkF4gnJnX_o2_f8neyXNjmc8KCKA,12607
22
+ glide_shared/commands/server_modules/ft_options/ft_aggregate_options.py,sha256=8b3sfsASS3Dr4eSNeRtn28gx8PjrRPOhoXZyoOmVF18,9928
23
+ glide_shared/commands/server_modules/ft_options/ft_constants.py,sha256=r9uLAExg2qThjwOBC8LxqXBITF0fwa5xfnD7EXnyPrw,1704
24
+ glide_shared/commands/server_modules/ft_options/ft_create_options.py,sha256=ll8AQPRe0_v10BdQXfCdN03bml3TEYbTWdaV3L5J_QU,13738
25
+ glide_shared/commands/server_modules/ft_options/ft_profile_options.py,sha256=yIapUTI_f7EI75BcVff9GpAZTT_GD1HS7QVhqjnyV6k,4283
26
+ glide_shared/commands/server_modules/ft_options/ft_search_options.py,sha256=imrnNhBaVsYjlknQpqitXDePoF8sXYdqQS4Ek_DXf7w,4872
27
+ glide_shared/commands/server_modules/json_batch.py,sha256=uqkLXPCOkzp53GfffnII1xA9ga0DefLYPnQ8ta899HE,36651
28
+ glide_shared/commands/server_modules/json_options.py,sha256=0dFk3EEtcERpmkNoO8930MqfEHLVaQRBRcg3CpL7nmE,3042
29
+ glide_shared/commands/sorted_set.py,sha256=hnXud0Ewn1uBdM6T2xzfCneZWfTeP-2U0XfEDGNCqlI,11466
30
+ glide_shared/commands/stream.py,sha256=MlllDP3teVX8BOB4ANb0JFC4RkUp8SQLCGlGMSPU_s4,15589
31
+ glide_shared/config.py,sha256=IScbmbbyemqw0TlkpqLgp2mFY48H2PtF2nE4K4mVGuc,43223
32
+ glide_shared/constants.py,sha256=pS7Xbjvq_qG3mlolVf51cCAGzXRhGdhvGIs2QK3R_b4,4375
33
+ glide_shared/exceptions.py,sha256=Z_szeAE-m1gsoBr5bPQymF6W6wiaunoHvBrt1dHbiYw,1852
34
+ glide_shared/protobuf/command_request_pb2.py,sha256=FIumn0p54n24pNykzWOoSGHQqvaY8-XopLWO0VqqKSI,19539
35
+ glide_shared/protobuf/connection_request_pb2.py,sha256=wlY76aIWKdyETOjD0Xh_B3RsfXqFwzkT0-lymAkTOes,6228
36
+ glide_shared/protobuf/response_pb2.py,sha256=oT2GHUwjrxvBVdINRKCvb3_BFN0Fq2wqwHbTj7KAX2E,2110
37
+ glide_shared/protobuf_codec.py,sha256=xwt4-D4WbvNIY_vjOd-00c73HOyNjWq7nN-Z718PBVA,3667
38
+ glide_shared/routes.py,sha256=HFccxCzXQXSi6Y1HFsRUm9ZcbJgCrar6y6uOWpGJWe0,4746
39
+ glide/glide.cpython-39-darwin.so,sha256=WLkGMxVvSZwDAQugX8lpE-Yryipb8iZgpIhdiN33Dn8,13757664
40
+ valkey_glide-2.2.2.dist-info/RECORD,,
glide/config.py DELETED
@@ -1,590 +0,0 @@
1
- # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
-
3
- from __future__ import annotations
4
-
5
- from dataclasses import dataclass
6
- from enum import Enum, IntEnum
7
- from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
8
-
9
- from glide.async_commands.core import CoreCommands
10
- from glide.exceptions import ConfigurationError
11
- from glide.protobuf.connection_request_pb2 import ConnectionRequest
12
- from glide.protobuf.connection_request_pb2 import ProtocolVersion as SentProtocolVersion
13
- from glide.protobuf.connection_request_pb2 import ReadFrom as ProtobufReadFrom
14
- from glide.protobuf.connection_request_pb2 import TlsMode
15
-
16
-
17
- class NodeAddress:
18
- def __init__(self, host: str = "localhost", port: int = 6379):
19
- """
20
- Represents the address and port of a node in the cluster.
21
-
22
- Args:
23
- host (str, optional): The server host. Defaults to "localhost".
24
- port (int, optional): The server port. Defaults to 6379.
25
- """
26
- self.host = host
27
- self.port = port
28
-
29
-
30
- class ReadFrom(Enum):
31
- """
32
- Represents the client's read from strategy.
33
- """
34
-
35
- PRIMARY = ProtobufReadFrom.Primary
36
- """
37
- Always get from primary, in order to get the freshest data.
38
- """
39
- PREFER_REPLICA = ProtobufReadFrom.PreferReplica
40
- """
41
- Spread the requests between all replicas in a round robin manner.
42
- If no replica is available, route the requests to the primary.
43
- """
44
- AZ_AFFINITY = ProtobufReadFrom.AZAffinity
45
- """
46
- Spread the read requests between replicas in the same client's AZ (Aviliablity zone) in a round robin manner,
47
- falling back to other replicas or the primary if needed
48
- """
49
- AZ_AFFINITY_REPLICAS_AND_PRIMARY = ProtobufReadFrom.AZAffinityReplicasAndPrimary
50
- """
51
- Spread the read requests among nodes within the client's Availability Zone (AZ) in a round robin manner,
52
- prioritizing local replicas, then the local primary, and falling back to any replica or the primary if needed.
53
- """
54
-
55
-
56
- class ProtocolVersion(Enum):
57
- """
58
- Represents the communication protocol with the server.
59
- """
60
-
61
- RESP2 = SentProtocolVersion.RESP2
62
- """
63
- Communicate using RESP2.
64
- """
65
- RESP3 = SentProtocolVersion.RESP3
66
- """
67
- Communicate using RESP3.
68
- """
69
-
70
-
71
- class BackoffStrategy:
72
- def __init__(self, num_of_retries: int, factor: int, exponent_base: int):
73
- """
74
- Represents the strategy used to determine how and when to reconnect, in case of connection failures.
75
- The time between attempts grows exponentially, to the formula rand(0 .. factor * (exponentBase ^ N)), where N
76
- is the number of failed attempts.
77
- Once the maximum value is reached, that will remain the time between retry attempts until a reconnect attempt is succesful.
78
- The client will attempt to reconnect indefinitely.
79
-
80
- Args:
81
- num_of_retries (int): Number of retry attempts that the client should perform when disconnected from the server,
82
- where the time between retries increases. Once the retries have reached the maximum value, the time between
83
- retries will remain constant until a reconnect attempt is succesful.
84
- factor (int): The multiplier that will be applied to the waiting time between each retry.
85
- exponent_base (int): The exponent base configured for the strategy.
86
- """
87
- self.num_of_retries = num_of_retries
88
- self.factor = factor
89
- self.exponent_base = exponent_base
90
-
91
-
92
- class ServerCredentials:
93
- def __init__(
94
- self,
95
- password: str,
96
- username: Optional[str] = None,
97
- ):
98
- """
99
- Represents the credentials for connecting to a server.
100
-
101
- Args:
102
- password (str): The password that will be used for authenticating connections to the servers.
103
- username (Optional[str]): The username that will be used for authenticating connections to the servers.
104
- If not supplied, "default" will be used.
105
- """
106
- self.password = password
107
- self.username = username
108
-
109
-
110
- class PeriodicChecksManualInterval:
111
- def __init__(self, duration_in_sec: int) -> None:
112
- """
113
- Represents a manually configured interval for periodic checks.
114
-
115
- Args:
116
- duration_in_sec (int): The duration in seconds for the interval between periodic checks.
117
- """
118
- self.duration_in_sec = duration_in_sec
119
-
120
-
121
- class PeriodicChecksStatus(Enum):
122
- """
123
- Represents the cluster's periodic checks status.
124
- To configure specific interval, see PeriodicChecksManualInterval.
125
- """
126
-
127
- ENABLED_DEFAULT_CONFIGS = 0
128
- """
129
- Enables the periodic checks with the default configurations.
130
- """
131
- DISABLED = 1
132
- """
133
- Disables the periodic checks.
134
- """
135
-
136
-
137
- class AdvancedBaseClientConfiguration:
138
- """
139
- Represents the advanced configuration settings for a base Glide client.
140
-
141
- Args:
142
- connection_timeout (Optional[int]): The duration in milliseconds to wait for a TCP/TLS connection to complete.
143
- This applies both during initial client creation and any reconnections that may occur during request processing.
144
- **Note**: A high connection timeout may lead to prolonged blocking of the entire command pipeline.
145
- If not explicitly set, a default value of 250 milliseconds will be used.
146
- """
147
-
148
- def __init__(self, connection_timeout: Optional[int] = None):
149
- self.connection_timeout = connection_timeout
150
-
151
- def _create_a_protobuf_conn_request(
152
- self, request: ConnectionRequest
153
- ) -> ConnectionRequest:
154
- if self.connection_timeout:
155
- request.connection_timeout = self.connection_timeout
156
- return request
157
-
158
-
159
- class BaseClientConfiguration:
160
- def __init__(
161
- self,
162
- addresses: List[NodeAddress],
163
- use_tls: bool = False,
164
- credentials: Optional[ServerCredentials] = None,
165
- read_from: ReadFrom = ReadFrom.PRIMARY,
166
- request_timeout: Optional[int] = None,
167
- client_name: Optional[str] = None,
168
- protocol: ProtocolVersion = ProtocolVersion.RESP3,
169
- inflight_requests_limit: Optional[int] = None,
170
- client_az: Optional[str] = None,
171
- advanced_config: Optional[AdvancedBaseClientConfiguration] = None,
172
- ):
173
- """
174
- Represents the configuration settings for a Glide client.
175
-
176
- Args:
177
- addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
178
- If the server is in cluster mode the list can be partial, as the client will attempt to map out
179
- the cluster and find all nodes.
180
- If the server is in standalone mode, only nodes whose addresses were provided will be used by the
181
- client.
182
- For example:
183
- [
184
- {address:sample-address-0001.use1.cache.amazonaws.com, port:6379},
185
- {address: sample-address-0002.use2.cache.amazonaws.com, port:6379}
186
- ].
187
- use_tls (bool): True if communication with the cluster should use Transport Level Security.
188
- Should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail
189
- credentials (ServerCredentials): Credentials for authentication process.
190
- If none are set, the client will not authenticate itself with the server.
191
- read_from (ReadFrom): If not set, `PRIMARY` will be used.
192
- request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete.
193
- This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries.
194
- If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not explicitly set, a default value of 250 milliseconds will be used.
195
- client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment.
196
- protocol (ProtocolVersion): Serialization protocol to be used. If not set, `RESP3` will be used.
197
- inflight_requests_limit (Optional[int]): The maximum number of concurrent requests allowed to be in-flight (sent but not yet completed).
198
- This limit is used to control the memory usage and prevent the client from overwhelming the server or getting stuck in case of a queue backlog.
199
- If not set, a default value will be used.
200
- client_az (Optional[str]): Availability Zone of the client.
201
- If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within the specified AZ if exits.
202
- If ReadFrom strategy is AZAffinityReplicasAndPrimary, this setting ensures that readonly commands are directed to nodes (first replicas then primary) within the specified AZ if they exist.
203
- advanced_config (Optional[AdvancedBaseClientConfiguration]): Advanced configuration settings for the client.
204
- """
205
- self.addresses = addresses
206
- self.use_tls = use_tls
207
- self.credentials = credentials
208
- self.read_from = read_from
209
- self.request_timeout = request_timeout
210
- self.client_name = client_name
211
- self.protocol = protocol
212
- self.inflight_requests_limit = inflight_requests_limit
213
- self.client_az = client_az
214
- self.advanced_config = advanced_config
215
-
216
- if read_from == ReadFrom.AZ_AFFINITY and not client_az:
217
- raise ValueError(
218
- "client_az must be set when read_from is set to AZ_AFFINITY"
219
- )
220
-
221
- if read_from == ReadFrom.AZ_AFFINITY_REPLICAS_AND_PRIMARY and not client_az:
222
- raise ValueError(
223
- "client_az must be set when read_from is set to AZ_AFFINITY_REPLICAS_AND_PRIMARY"
224
- )
225
-
226
- def _create_a_protobuf_conn_request(
227
- self, cluster_mode: bool = False
228
- ) -> ConnectionRequest:
229
- """
230
- Generates a Protobuf ConnectionRequest using the values from this ClientConfiguration.
231
-
232
- Args:
233
- cluster_mode (bool, optional): The cluster mode of the client. Defaults to False.
234
-
235
- Returns:
236
- ConnectionRequest: Protobuf ConnectionRequest.
237
- """
238
- request = ConnectionRequest()
239
- for address in self.addresses:
240
- address_info = request.addresses.add()
241
- address_info.host = address.host
242
- address_info.port = address.port
243
- request.tls_mode = TlsMode.SecureTls if self.use_tls else TlsMode.NoTls
244
- request.read_from = self.read_from.value
245
- if self.request_timeout:
246
- request.request_timeout = self.request_timeout
247
- request.cluster_mode_enabled = True if cluster_mode else False
248
- if self.credentials:
249
- if self.credentials.username:
250
- request.authentication_info.username = self.credentials.username
251
- request.authentication_info.password = self.credentials.password
252
- if self.client_name:
253
- request.client_name = self.client_name
254
- request.protocol = self.protocol.value
255
- if self.inflight_requests_limit:
256
- request.inflight_requests_limit = self.inflight_requests_limit
257
- if self.client_az:
258
- request.client_az = self.client_az
259
- if self.advanced_config:
260
- self.advanced_config._create_a_protobuf_conn_request(request)
261
-
262
- return request
263
-
264
- def _is_pubsub_configured(self) -> bool:
265
- return False
266
-
267
- def _get_pubsub_callback_and_context(
268
- self,
269
- ) -> Tuple[Optional[Callable[[CoreCommands.PubSubMsg, Any], None]], Any]:
270
- return None, None
271
-
272
-
273
- class AdvancedGlideClientConfiguration(AdvancedBaseClientConfiguration):
274
- """
275
- Represents the advanced configuration settings for a Standalone Glide client.
276
- """
277
-
278
- def __init__(self, connection_timeout: Optional[int] = None):
279
-
280
- super().__init__(connection_timeout)
281
-
282
-
283
- class GlideClientConfiguration(BaseClientConfiguration):
284
- """
285
- Represents the configuration settings for a Standalone Glide client.
286
-
287
- Args:
288
- addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
289
- Only nodes whose addresses were provided will be used by the client.
290
- For example:
291
- [
292
- {address:sample-address-0001.use1.cache.amazonaws.com, port:6379},
293
- {address: sample-address-0002.use2.cache.amazonaws.com, port:6379}
294
- ].
295
- use_tls (bool): True if communication with the cluster should use Transport Level Security.
296
- credentials (ServerCredentials): Credentials for authentication process.
297
- If none are set, the client will not authenticate itself with the server.
298
- read_from (ReadFrom): If not set, `PRIMARY` will be used.
299
- request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete.
300
- This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries.
301
- If the specified timeout is exceeded for a pending request, it will result in a timeout error.
302
- If not explicitly set, a default value of 250 milliseconds will be used.
303
- reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of
304
- connection failures.
305
- If not set, a default backoff strategy will be used.
306
- database_id (Optional[int]): index of the logical database to connect to.
307
- client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment.
308
- protocol (ProtocolVersion): The version of the RESP protocol to communicate with the server.
309
- pubsub_subscriptions (Optional[GlideClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used for the client.
310
- Will be applied via SUBSCRIBE/PSUBSCRIBE commands during connection establishment.
311
- inflight_requests_limit (Optional[int]): The maximum number of concurrent requests allowed to be in-flight (sent but not yet completed).
312
- This limit is used to control the memory usage and prevent the client from overwhelming the server or getting stuck in case of a queue backlog.
313
- If not set, a default value will be used.
314
- client_az (Optional[str]): Availability Zone of the client.
315
- If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within the specified AZ if exits.
316
- If ReadFrom strategy is AZAffinityReplicasAndPrimary, this setting ensures that readonly commands are directed to nodes (first replicas then primary) within the specified AZ if they exist.
317
- advanced_config (Optional[AdvancedGlideClientConfiguration]): Advanced configuration settings for the client, see `AdvancedGlideClientConfiguration`.
318
- """
319
-
320
- class PubSubChannelModes(IntEnum):
321
- """
322
- Describes pubsub subsciption modes.
323
- See https://valkey.io/docs/topics/pubsub/ for more details
324
- """
325
-
326
- Exact = 0
327
- """ Use exact channel names """
328
- Pattern = 1
329
- """ Use channel name patterns """
330
-
331
- @dataclass
332
- class PubSubSubscriptions:
333
- """Describes pubsub configuration for standalone mode client.
334
-
335
- Attributes:
336
- channels_and_patterns (Dict[GlideClientConfiguration.PubSubChannelModes, Set[str]]):
337
- Channels and patterns by modes.
338
- callback (Optional[Callable[[CoreCommands.PubSubMsg, Any], None]]):
339
- Optional callback to accept the incomming messages.
340
- context (Any):
341
- Arbitrary context to pass to the callback.
342
- """
343
-
344
- channels_and_patterns: Dict[
345
- GlideClientConfiguration.PubSubChannelModes, Set[str]
346
- ]
347
- callback: Optional[Callable[[CoreCommands.PubSubMsg, Any], None]]
348
- context: Any
349
-
350
- def __init__(
351
- self,
352
- addresses: List[NodeAddress],
353
- use_tls: bool = False,
354
- credentials: Optional[ServerCredentials] = None,
355
- read_from: ReadFrom = ReadFrom.PRIMARY,
356
- request_timeout: Optional[int] = None,
357
- reconnect_strategy: Optional[BackoffStrategy] = None,
358
- database_id: Optional[int] = None,
359
- client_name: Optional[str] = None,
360
- protocol: ProtocolVersion = ProtocolVersion.RESP3,
361
- pubsub_subscriptions: Optional[PubSubSubscriptions] = None,
362
- inflight_requests_limit: Optional[int] = None,
363
- client_az: Optional[str] = None,
364
- advanced_config: Optional[AdvancedGlideClientConfiguration] = None,
365
- ):
366
- super().__init__(
367
- addresses=addresses,
368
- use_tls=use_tls,
369
- credentials=credentials,
370
- read_from=read_from,
371
- request_timeout=request_timeout,
372
- client_name=client_name,
373
- protocol=protocol,
374
- inflight_requests_limit=inflight_requests_limit,
375
- client_az=client_az,
376
- advanced_config=advanced_config,
377
- )
378
- self.reconnect_strategy = reconnect_strategy
379
- self.database_id = database_id
380
- self.pubsub_subscriptions = pubsub_subscriptions
381
-
382
- def _create_a_protobuf_conn_request(
383
- self, cluster_mode: bool = False
384
- ) -> ConnectionRequest:
385
- assert cluster_mode is False
386
- request = super()._create_a_protobuf_conn_request(cluster_mode)
387
- if self.reconnect_strategy:
388
- request.connection_retry_strategy.number_of_retries = (
389
- self.reconnect_strategy.num_of_retries
390
- )
391
- request.connection_retry_strategy.factor = self.reconnect_strategy.factor
392
- request.connection_retry_strategy.exponent_base = (
393
- self.reconnect_strategy.exponent_base
394
- )
395
- if self.database_id:
396
- request.database_id = self.database_id
397
-
398
- if self.pubsub_subscriptions:
399
- if self.protocol == ProtocolVersion.RESP2:
400
- raise ConfigurationError(
401
- "PubSub subscriptions require RESP3 protocol, but RESP2 was configured."
402
- )
403
- if (
404
- self.pubsub_subscriptions.context is not None
405
- and not self.pubsub_subscriptions.callback
406
- ):
407
- raise ConfigurationError(
408
- "PubSub subscriptions with a context require a callback function to be configured."
409
- )
410
- for (
411
- channel_type,
412
- channels_patterns,
413
- ) in self.pubsub_subscriptions.channels_and_patterns.items():
414
- entry = request.pubsub_subscriptions.channels_or_patterns_by_type[
415
- int(channel_type)
416
- ]
417
- for channel_pattern in channels_patterns:
418
- entry.channels_or_patterns.append(str.encode(channel_pattern))
419
-
420
- return request
421
-
422
- def _is_pubsub_configured(self) -> bool:
423
- return self.pubsub_subscriptions is not None
424
-
425
- def _get_pubsub_callback_and_context(
426
- self,
427
- ) -> Tuple[Optional[Callable[[CoreCommands.PubSubMsg, Any], None]], Any]:
428
- if self.pubsub_subscriptions:
429
- return self.pubsub_subscriptions.callback, self.pubsub_subscriptions.context
430
- return None, None
431
-
432
-
433
- class AdvancedGlideClusterClientConfiguration(AdvancedBaseClientConfiguration):
434
- """
435
- Represents the advanced configuration settings for a Glide Cluster client.
436
- """
437
-
438
- def __init__(self, connection_timeout: Optional[int] = None):
439
- super().__init__(connection_timeout)
440
-
441
-
442
- class GlideClusterClientConfiguration(BaseClientConfiguration):
443
- """
444
- Represents the configuration settings for a Cluster Glide client.
445
-
446
- Args:
447
- addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
448
- The list can be partial, as the client will attempt to map out the cluster and find all nodes.
449
- For example:
450
- [
451
- {address:configuration-endpoint.use1.cache.amazonaws.com, port:6379}
452
- ].
453
- use_tls (bool): True if communication with the cluster should use Transport Level Security.
454
- credentials (ServerCredentials): Credentials for authentication process.
455
- If none are set, the client will not authenticate itself with the server.
456
- read_from (ReadFrom): If not set, `PRIMARY` will be used.
457
- request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete.
458
- This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries.
459
- If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not explicitly set, a default value of 250 milliseconds will be used.
460
- client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment.
461
- protocol (ProtocolVersion): The version of the RESP protocol to communicate with the server.
462
- periodic_checks (Union[PeriodicChecksStatus, PeriodicChecksManualInterval]): Configure the periodic topology checks.
463
- These checks evaluate changes in the cluster's topology, triggering a slot refresh when detected.
464
- Periodic checks ensure a quick and efficient process by querying a limited number of nodes.
465
- Defaults to PeriodicChecksStatus.ENABLED_DEFAULT_CONFIGS.
466
- pubsub_subscriptions (Optional[GlideClusterClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used for the client.
467
- Will be applied via SUBSCRIBE/PSUBSCRIBE/SSUBSCRIBE commands during connection establishment.
468
- inflight_requests_limit (Optional[int]): The maximum number of concurrent requests allowed to be in-flight (sent but not yet completed).
469
- This limit is used to control the memory usage and prevent the client from overwhelming the server or getting stuck in case of a queue backlog.
470
- If not set, a default value will be used.
471
- client_az (Optional[str]): Availability Zone of the client.
472
- If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within the specified AZ if exits.
473
- If ReadFrom strategy is AZAffinityReplicasAndPrimary, this setting ensures that readonly commands are directed to nodes (first replicas then primary) within the specified AZ if they exist.
474
- advanced_config (Optional[AdvancedGlideClusterClientConfiguration]) : Advanced configuration settings for the client, see `AdvancedGlideClusterClientConfiguration`.
475
-
476
-
477
- Notes:
478
- Currently, the reconnection strategy in cluster mode is not configurable, and exponential backoff
479
- with fixed values is used.
480
- """
481
-
482
- class PubSubChannelModes(IntEnum):
483
- """
484
- Describes pubsub subsciption modes.
485
- See https://valkey.io/docs/topics/pubsub/ for more details
486
- """
487
-
488
- Exact = 0
489
- """ Use exact channel names """
490
- Pattern = 1
491
- """ Use channel name patterns """
492
- Sharded = 2
493
- """ Use sharded pubsub. Available since Valkey version 7.0. """
494
-
495
- @dataclass
496
- class PubSubSubscriptions:
497
- """Describes pubsub configuration for cluster mode client.
498
-
499
- Attributes:
500
- channels_and_patterns (Dict[GlideClusterClientConfiguration.PubSubChannelModes, Set[str]]):
501
- Channels and patterns by modes.
502
- callback (Optional[Callable[[CoreCommands.PubSubMsg, Any], None]]):
503
- Optional callback to accept the incoming messages.
504
- context (Any):
505
- Arbitrary context to pass to the callback.
506
- """
507
-
508
- channels_and_patterns: Dict[
509
- GlideClusterClientConfiguration.PubSubChannelModes, Set[str]
510
- ]
511
- callback: Optional[Callable[[CoreCommands.PubSubMsg, Any], None]]
512
- context: Any
513
-
514
- def __init__(
515
- self,
516
- addresses: List[NodeAddress],
517
- use_tls: bool = False,
518
- credentials: Optional[ServerCredentials] = None,
519
- read_from: ReadFrom = ReadFrom.PRIMARY,
520
- request_timeout: Optional[int] = None,
521
- client_name: Optional[str] = None,
522
- protocol: ProtocolVersion = ProtocolVersion.RESP3,
523
- periodic_checks: Union[
524
- PeriodicChecksStatus, PeriodicChecksManualInterval
525
- ] = PeriodicChecksStatus.ENABLED_DEFAULT_CONFIGS,
526
- pubsub_subscriptions: Optional[PubSubSubscriptions] = None,
527
- inflight_requests_limit: Optional[int] = None,
528
- client_az: Optional[str] = None,
529
- advanced_config: Optional[AdvancedGlideClusterClientConfiguration] = None,
530
- ):
531
- super().__init__(
532
- addresses=addresses,
533
- use_tls=use_tls,
534
- credentials=credentials,
535
- read_from=read_from,
536
- request_timeout=request_timeout,
537
- client_name=client_name,
538
- protocol=protocol,
539
- inflight_requests_limit=inflight_requests_limit,
540
- client_az=client_az,
541
- advanced_config=advanced_config,
542
- )
543
- self.periodic_checks = periodic_checks
544
- self.pubsub_subscriptions = pubsub_subscriptions
545
-
546
- def _create_a_protobuf_conn_request(
547
- self, cluster_mode: bool = False
548
- ) -> ConnectionRequest:
549
- assert cluster_mode is True
550
- request = super()._create_a_protobuf_conn_request(cluster_mode)
551
- if type(self.periodic_checks) is PeriodicChecksManualInterval:
552
- request.periodic_checks_manual_interval.duration_in_sec = (
553
- self.periodic_checks.duration_in_sec
554
- )
555
- elif self.periodic_checks == PeriodicChecksStatus.DISABLED:
556
- request.periodic_checks_disabled.SetInParent()
557
-
558
- if self.pubsub_subscriptions:
559
- if self.protocol == ProtocolVersion.RESP2:
560
- raise ConfigurationError(
561
- "PubSub subscriptions require RESP3 protocol, but RESP2 was configured."
562
- )
563
- if (
564
- self.pubsub_subscriptions.context is not None
565
- and not self.pubsub_subscriptions.callback
566
- ):
567
- raise ConfigurationError(
568
- "PubSub subscriptions with a context require a callback function to be configured."
569
- )
570
- for (
571
- channel_type,
572
- channels_patterns,
573
- ) in self.pubsub_subscriptions.channels_and_patterns.items():
574
- entry = request.pubsub_subscriptions.channels_or_patterns_by_type[
575
- int(channel_type)
576
- ]
577
- for channel_pattern in channels_patterns:
578
- entry.channels_or_patterns.append(str.encode(channel_pattern))
579
-
580
- return request
581
-
582
- def _is_pubsub_configured(self) -> bool:
583
- return self.pubsub_subscriptions is not None
584
-
585
- def _get_pubsub_callback_and_context(
586
- self,
587
- ) -> Tuple[Optional[Callable[[CoreCommands.PubSubMsg, Any], None]], Any]:
588
- if self.pubsub_subscriptions:
589
- return self.pubsub_subscriptions.callback, self.pubsub_subscriptions.context
590
- return None, None