valkey-glide 1.3.5rc5__cp312-cp312-macosx_11_0_arm64.whl → 2.0.0__cp312-cp312-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.
- glide/__init__.py +32 -8
- glide/async_commands/{transaction.py → batch.py} +1420 -992
- glide/async_commands/batch_options.py +261 -0
- glide/async_commands/bitmap.py +94 -85
- glide/async_commands/cluster_commands.py +293 -126
- glide/async_commands/command_args.py +7 -6
- glide/async_commands/core.py +1313 -721
- glide/async_commands/server_modules/ft.py +83 -14
- glide/async_commands/server_modules/ft_options/ft_aggregate_options.py +15 -8
- glide/async_commands/server_modules/ft_options/ft_create_options.py +23 -11
- glide/async_commands/server_modules/ft_options/ft_profile_options.py +12 -7
- glide/async_commands/server_modules/ft_options/ft_search_options.py +12 -6
- glide/async_commands/server_modules/glide_json.py +134 -43
- glide/async_commands/server_modules/json_batch.py +157 -127
- glide/async_commands/sorted_set.py +39 -29
- glide/async_commands/standalone_commands.py +202 -95
- glide/async_commands/stream.py +94 -87
- glide/config.py +253 -112
- glide/constants.py +8 -4
- glide/glide.cpython-312-darwin.so +0 -0
- glide/glide.pyi +25 -0
- glide/glide_client.py +305 -94
- glide/logger.py +31 -19
- glide/opentelemetry.py +181 -0
- glide/protobuf/command_request_pb2.py +15 -15
- glide/protobuf/command_request_pb2.pyi +75 -46
- glide/protobuf/connection_request_pb2.py +12 -12
- glide/protobuf/connection_request_pb2.pyi +36 -29
- glide/protobuf/response_pb2.py +6 -6
- glide/protobuf/response_pb2.pyi +14 -9
- glide/protobuf_codec.py +7 -6
- glide/routes.py +41 -8
- {valkey_glide-1.3.5rc5.dist-info → valkey_glide-2.0.0.dist-info}/METADATA +38 -14
- valkey_glide-2.0.0.dist-info/RECORD +39 -0
- valkey_glide-1.3.5rc5.dist-info/RECORD +0 -37
- {valkey_glide-1.3.5rc5.dist-info → valkey_glide-2.0.0.dist-info}/WHEEL +0 -0
glide/config.py
CHANGED
|
@@ -15,14 +15,15 @@ from glide.protobuf.connection_request_pb2 import TlsMode
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class NodeAddress:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Represents the address and port of a node in the cluster.
|
|
18
|
+
"""
|
|
19
|
+
Represents the address and port of a node in the cluster.
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
Attributes:
|
|
22
|
+
host (str, optional): The server host. Defaults to "localhost".
|
|
23
|
+
port (int, optional): The server port. Defaults to 6379.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, host: str = "localhost", port: int = 6379):
|
|
26
27
|
self.host = host
|
|
27
28
|
self.port = port
|
|
28
29
|
|
|
@@ -69,52 +70,64 @@ class ProtocolVersion(Enum):
|
|
|
69
70
|
|
|
70
71
|
|
|
71
72
|
class BackoffStrategy:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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, and `rand(...)` applies a jitter of up to `jitter_percent`% to introduce randomness and reduce retry storms.
|
|
77
|
+
Once the maximum value is reached, that will remain the time between retry attempts until a reconnect attempt is
|
|
78
|
+
successful.
|
|
79
|
+
The client will attempt to reconnect indefinitely.
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
Attributes:
|
|
82
|
+
num_of_retries (int): Number of retry attempts that the client should perform when disconnected from the server,
|
|
83
|
+
where the time between retries increases. Once the retries have reached the maximum value, the time between
|
|
84
|
+
retries will remain constant until a reconnect attempt is succesful.
|
|
85
|
+
factor (int): The multiplier that will be applied to the waiting time between each retry.
|
|
86
|
+
exponent_base (int): The exponent base configured for the strategy.
|
|
87
|
+
jitter_percent (Optional[int]): The Jitter percent on the calculated duration. If not set, a default value will be used.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def __init__(
|
|
91
|
+
self,
|
|
92
|
+
num_of_retries: int,
|
|
93
|
+
factor: int,
|
|
94
|
+
exponent_base: int,
|
|
95
|
+
jitter_percent: Optional[int] = None,
|
|
96
|
+
):
|
|
87
97
|
self.num_of_retries = num_of_retries
|
|
88
98
|
self.factor = factor
|
|
89
99
|
self.exponent_base = exponent_base
|
|
100
|
+
self.jitter_percent = jitter_percent
|
|
90
101
|
|
|
91
102
|
|
|
92
103
|
class ServerCredentials:
|
|
104
|
+
"""
|
|
105
|
+
Represents the credentials for connecting to a server.
|
|
106
|
+
|
|
107
|
+
Attributes:
|
|
108
|
+
password (str): The password that will be used for authenticating connections to the servers.
|
|
109
|
+
username (Optional[str]): The username that will be used for authenticating connections to the servers.
|
|
110
|
+
If not supplied, "default" will be used.
|
|
111
|
+
"""
|
|
112
|
+
|
|
93
113
|
def __init__(
|
|
94
114
|
self,
|
|
95
115
|
password: str,
|
|
96
116
|
username: Optional[str] = None,
|
|
97
117
|
):
|
|
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
118
|
self.password = password
|
|
107
119
|
self.username = username
|
|
108
120
|
|
|
109
121
|
|
|
110
122
|
class PeriodicChecksManualInterval:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Represents a manually configured interval for periodic checks.
|
|
123
|
+
"""
|
|
124
|
+
Represents a manually configured interval for periodic checks.
|
|
114
125
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
Attributes:
|
|
127
|
+
duration_in_sec (int): The duration in seconds for the interval between periodic checks.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
def __init__(self, duration_in_sec: int) -> None:
|
|
118
131
|
self.duration_in_sec = duration_in_sec
|
|
119
132
|
|
|
120
133
|
|
|
@@ -134,29 +147,136 @@ class PeriodicChecksStatus(Enum):
|
|
|
134
147
|
"""
|
|
135
148
|
|
|
136
149
|
|
|
150
|
+
class TlsAdvancedConfiguration:
|
|
151
|
+
"""
|
|
152
|
+
Represents advanced TLS configuration settings.
|
|
153
|
+
|
|
154
|
+
Attributes:
|
|
155
|
+
use_insecure_tls (Optional[bool]): Whether to bypass TLS certificate verification.
|
|
156
|
+
|
|
157
|
+
- When set to True, the client skips certificate validation.
|
|
158
|
+
This is useful when connecting to servers or clusters using self-signed certificates,
|
|
159
|
+
or when DNS entries (e.g., CNAMEs) don't match certificate hostnames.
|
|
160
|
+
|
|
161
|
+
- This setting is typically used in development or testing environments. **It is
|
|
162
|
+
strongly discouraged in production**, as it introduces security risks such as man-in-the-middle attacks.
|
|
163
|
+
|
|
164
|
+
- Only valid if TLS is already enabled in the base client configuration.
|
|
165
|
+
Enabling it without TLS will result in a `ConfigurationError`.
|
|
166
|
+
|
|
167
|
+
- Default: False (verification is enforced).
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
def __init__(self, use_insecure_tls: Optional[bool] = None):
|
|
171
|
+
self.use_insecure_tls = use_insecure_tls
|
|
172
|
+
|
|
173
|
+
|
|
137
174
|
class AdvancedBaseClientConfiguration:
|
|
138
175
|
"""
|
|
139
176
|
Represents the advanced configuration settings for a base Glide client.
|
|
140
177
|
|
|
141
|
-
|
|
178
|
+
Attributes:
|
|
142
179
|
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
|
|
180
|
+
This applies both during initial client creation and any reconnection that may occur during request processing.
|
|
144
181
|
**Note**: A high connection timeout may lead to prolonged blocking of the entire command pipeline.
|
|
145
|
-
If not explicitly set, a default value of
|
|
182
|
+
If not explicitly set, a default value of 2000 milliseconds will be used.
|
|
183
|
+
tls_config (Optional[TlsAdvancedConfiguration]): The advanced TLS configuration settings.
|
|
184
|
+
This allows for more granular control of TLS behavior, such as enabling an insecure mode
|
|
185
|
+
that bypasses certificate validation.
|
|
146
186
|
"""
|
|
147
187
|
|
|
148
|
-
def __init__(
|
|
188
|
+
def __init__(
|
|
189
|
+
self,
|
|
190
|
+
connection_timeout: Optional[int] = None,
|
|
191
|
+
tls_config: Optional[TlsAdvancedConfiguration] = None,
|
|
192
|
+
):
|
|
149
193
|
self.connection_timeout = connection_timeout
|
|
194
|
+
self.tls_config = tls_config
|
|
150
195
|
|
|
151
196
|
def _create_a_protobuf_conn_request(
|
|
152
197
|
self, request: ConnectionRequest
|
|
153
198
|
) -> ConnectionRequest:
|
|
154
199
|
if self.connection_timeout:
|
|
155
200
|
request.connection_timeout = self.connection_timeout
|
|
201
|
+
|
|
202
|
+
if self.tls_config and self.tls_config.use_insecure_tls:
|
|
203
|
+
if request.tls_mode == TlsMode.SecureTls:
|
|
204
|
+
request.tls_mode = TlsMode.InsecureTls
|
|
205
|
+
elif request.tls_mode == TlsMode.NoTls:
|
|
206
|
+
raise ConfigurationError(
|
|
207
|
+
"use_insecure_tls cannot be enabled when use_tls is disabled."
|
|
208
|
+
)
|
|
209
|
+
|
|
156
210
|
return request
|
|
157
211
|
|
|
158
212
|
|
|
159
213
|
class BaseClientConfiguration:
|
|
214
|
+
"""
|
|
215
|
+
Represents the configuration settings for a Glide client.
|
|
216
|
+
|
|
217
|
+
Attributes:
|
|
218
|
+
addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
|
|
219
|
+
If the server is in cluster mode the list can be partial, as the client will attempt to map out
|
|
220
|
+
the cluster and find all nodes.
|
|
221
|
+
If the server is in standalone mode, only nodes whose addresses were provided will be used by the
|
|
222
|
+
client.
|
|
223
|
+
For example::
|
|
224
|
+
|
|
225
|
+
[
|
|
226
|
+
{address:sample-address-0001.use1.cache.amazonaws.com, port:6379},
|
|
227
|
+
{address: sample-address-0002.use2.cache.amazonaws.com, port:6379}
|
|
228
|
+
].
|
|
229
|
+
|
|
230
|
+
use_tls (bool): True if communication with the cluster should use Transport Level Security.
|
|
231
|
+
Should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail.
|
|
232
|
+
For advanced tls configuration, please use `AdvancedBaseClientConfiguration`.
|
|
233
|
+
credentials (ServerCredentials): Credentials for authentication process.
|
|
234
|
+
If none are set, the client will not authenticate itself with the server.
|
|
235
|
+
read_from (ReadFrom): If not set, `PRIMARY` will be used.
|
|
236
|
+
request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to
|
|
237
|
+
complete.
|
|
238
|
+
This duration encompasses sending the request, awaiting for a response from the server, and any required
|
|
239
|
+
reconnection or retries.
|
|
240
|
+
If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not
|
|
241
|
+
explicitly set, a default value of 250 milliseconds will be used.
|
|
242
|
+
reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of
|
|
243
|
+
connection failures.
|
|
244
|
+
If not set, a default backoff strategy will be used.
|
|
245
|
+
client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command
|
|
246
|
+
during connection establishment.
|
|
247
|
+
protocol (ProtocolVersion): Serialization protocol to be used. If not set, `RESP3` will be used.
|
|
248
|
+
inflight_requests_limit (Optional[int]): The maximum number of concurrent requests allowed to be in-flight
|
|
249
|
+
(sent but not yet completed).
|
|
250
|
+
This limit is used to control the memory usage and prevent the client from overwhelming the server or getting
|
|
251
|
+
stuck in case of a queue backlog.
|
|
252
|
+
If not set, a default value will be used.
|
|
253
|
+
client_az (Optional[str]): Availability Zone of the client.
|
|
254
|
+
If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas
|
|
255
|
+
within the specified AZ if exits.
|
|
256
|
+
If ReadFrom strategy is AZAffinityReplicasAndPrimary, this setting ensures that readonly commands are directed
|
|
257
|
+
to nodes (first replicas then primary) within the specified AZ if they exist.
|
|
258
|
+
advanced_config (Optional[AdvancedBaseClientConfiguration]): Advanced configuration settings for the client.
|
|
259
|
+
|
|
260
|
+
lazy_connect (Optional[bool]): Enables lazy connection mode, where physical connections to the server(s)
|
|
261
|
+
are deferred until the first command is sent. This can reduce startup latency and allow for client
|
|
262
|
+
creation in disconnected environments.
|
|
263
|
+
|
|
264
|
+
When set to `True`, the client will not attempt to connect to the specified nodes during
|
|
265
|
+
initialization. Instead, connections will be established only when a command is actually executed.
|
|
266
|
+
|
|
267
|
+
Note that the first command executed with lazy connections may experience additional latency
|
|
268
|
+
as it needs to establish the connection first. During this initial connection, the standard
|
|
269
|
+
request timeout does not apply yet - instead, the connection establishment is governed by
|
|
270
|
+
`AdvancedBaseClientConfiguration.connection_timeout`. The request timeout (`request_timeout`)
|
|
271
|
+
only begins counting after the connection has been successfully established. This behavior
|
|
272
|
+
can effectively increase the total time needed for the first command to complete.
|
|
273
|
+
|
|
274
|
+
This setting applies to both standalone and cluster modes. Note that if an operation is
|
|
275
|
+
attempted and connection fails (e.g., unreachable nodes), errors will surface at that point.
|
|
276
|
+
|
|
277
|
+
If not set, connections are established immediately during client creation (equivalent to `False`).
|
|
278
|
+
"""
|
|
279
|
+
|
|
160
280
|
def __init__(
|
|
161
281
|
self,
|
|
162
282
|
addresses: List[NodeAddress],
|
|
@@ -164,54 +284,26 @@ class BaseClientConfiguration:
|
|
|
164
284
|
credentials: Optional[ServerCredentials] = None,
|
|
165
285
|
read_from: ReadFrom = ReadFrom.PRIMARY,
|
|
166
286
|
request_timeout: Optional[int] = None,
|
|
287
|
+
reconnect_strategy: Optional[BackoffStrategy] = None,
|
|
167
288
|
client_name: Optional[str] = None,
|
|
168
289
|
protocol: ProtocolVersion = ProtocolVersion.RESP3,
|
|
169
290
|
inflight_requests_limit: Optional[int] = None,
|
|
170
291
|
client_az: Optional[str] = None,
|
|
171
292
|
advanced_config: Optional[AdvancedBaseClientConfiguration] = None,
|
|
293
|
+
lazy_connect: Optional[bool] = None,
|
|
172
294
|
):
|
|
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
295
|
self.addresses = addresses
|
|
206
296
|
self.use_tls = use_tls
|
|
207
297
|
self.credentials = credentials
|
|
208
298
|
self.read_from = read_from
|
|
209
299
|
self.request_timeout = request_timeout
|
|
300
|
+
self.reconnect_strategy = reconnect_strategy
|
|
210
301
|
self.client_name = client_name
|
|
211
302
|
self.protocol = protocol
|
|
212
303
|
self.inflight_requests_limit = inflight_requests_limit
|
|
213
304
|
self.client_az = client_az
|
|
214
305
|
self.advanced_config = advanced_config
|
|
306
|
+
self.lazy_connect = lazy_connect
|
|
215
307
|
|
|
216
308
|
if read_from == ReadFrom.AZ_AFFINITY and not client_az:
|
|
217
309
|
raise ValueError(
|
|
@@ -244,6 +336,19 @@ class BaseClientConfiguration:
|
|
|
244
336
|
request.read_from = self.read_from.value
|
|
245
337
|
if self.request_timeout:
|
|
246
338
|
request.request_timeout = self.request_timeout
|
|
339
|
+
if self.reconnect_strategy:
|
|
340
|
+
request.connection_retry_strategy.number_of_retries = (
|
|
341
|
+
self.reconnect_strategy.num_of_retries
|
|
342
|
+
)
|
|
343
|
+
request.connection_retry_strategy.factor = self.reconnect_strategy.factor
|
|
344
|
+
request.connection_retry_strategy.exponent_base = (
|
|
345
|
+
self.reconnect_strategy.exponent_base
|
|
346
|
+
)
|
|
347
|
+
if self.reconnect_strategy.jitter_percent is not None:
|
|
348
|
+
request.connection_retry_strategy.jitter_percent = (
|
|
349
|
+
self.reconnect_strategy.jitter_percent
|
|
350
|
+
)
|
|
351
|
+
|
|
247
352
|
request.cluster_mode_enabled = True if cluster_mode else False
|
|
248
353
|
if self.credentials:
|
|
249
354
|
if self.credentials.username:
|
|
@@ -259,6 +364,8 @@ class BaseClientConfiguration:
|
|
|
259
364
|
if self.advanced_config:
|
|
260
365
|
self.advanced_config._create_a_protobuf_conn_request(request)
|
|
261
366
|
|
|
367
|
+
if self.lazy_connect is not None:
|
|
368
|
+
request.lazy_connect = self.lazy_connect
|
|
262
369
|
return request
|
|
263
370
|
|
|
264
371
|
def _is_pubsub_configured(self) -> bool:
|
|
@@ -275,52 +382,67 @@ class AdvancedGlideClientConfiguration(AdvancedBaseClientConfiguration):
|
|
|
275
382
|
Represents the advanced configuration settings for a Standalone Glide client.
|
|
276
383
|
"""
|
|
277
384
|
|
|
278
|
-
def __init__(
|
|
385
|
+
def __init__(
|
|
386
|
+
self,
|
|
387
|
+
connection_timeout: Optional[int] = None,
|
|
388
|
+
tls_config: Optional[TlsAdvancedConfiguration] = None,
|
|
389
|
+
):
|
|
279
390
|
|
|
280
|
-
super().__init__(connection_timeout)
|
|
391
|
+
super().__init__(connection_timeout, tls_config)
|
|
281
392
|
|
|
282
393
|
|
|
283
394
|
class GlideClientConfiguration(BaseClientConfiguration):
|
|
284
395
|
"""
|
|
285
396
|
Represents the configuration settings for a Standalone Glide client.
|
|
286
397
|
|
|
287
|
-
|
|
398
|
+
Attributes:
|
|
288
399
|
addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
|
|
289
|
-
|
|
290
|
-
|
|
400
|
+
Only nodes whose addresses were provided will be used by the client.
|
|
401
|
+
For example::
|
|
402
|
+
|
|
291
403
|
[
|
|
292
404
|
{address:sample-address-0001.use1.cache.amazonaws.com, port:6379},
|
|
293
405
|
{address: sample-address-0002.use2.cache.amazonaws.com, port:6379}
|
|
294
|
-
]
|
|
406
|
+
]
|
|
407
|
+
|
|
295
408
|
use_tls (bool): True if communication with the cluster should use Transport Level Security.
|
|
409
|
+
Please use `AdvancedGlideClusterClientConfiguration`.
|
|
296
410
|
credentials (ServerCredentials): Credentials for authentication process.
|
|
297
411
|
If none are set, the client will not authenticate itself with the server.
|
|
298
412
|
read_from (ReadFrom): If not set, `PRIMARY` will be used.
|
|
299
413
|
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
|
|
414
|
+
This duration encompasses sending the request, awaiting for a response from the server, and any required
|
|
415
|
+
reconnection or retries.
|
|
301
416
|
If the specified timeout is exceeded for a pending request, it will result in a timeout error.
|
|
302
417
|
If not explicitly set, a default value of 250 milliseconds will be used.
|
|
303
418
|
reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of
|
|
304
419
|
connection failures.
|
|
305
420
|
If not set, a default backoff strategy will be used.
|
|
306
421
|
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
|
|
422
|
+
client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during
|
|
423
|
+
connection establishment.
|
|
308
424
|
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
|
|
425
|
+
pubsub_subscriptions (Optional[GlideClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used for the
|
|
426
|
+
client.
|
|
310
427
|
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
|
|
312
|
-
|
|
428
|
+
inflight_requests_limit (Optional[int]): The maximum number of concurrent requests allowed to be in-flight
|
|
429
|
+
(sent but not yet completed).
|
|
430
|
+
This limit is used to control the memory usage and prevent the client from overwhelming the server or getting
|
|
431
|
+
stuck in case of a queue backlog.
|
|
313
432
|
If not set, a default value will be used.
|
|
314
433
|
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
|
|
316
|
-
|
|
317
|
-
|
|
434
|
+
If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within
|
|
435
|
+
the specified AZ if exits.
|
|
436
|
+
If ReadFrom strategy is AZAffinityReplicasAndPrimary, this setting ensures that readonly commands are directed to
|
|
437
|
+
nodes (first replicas then primary) within the specified AZ if they exist.
|
|
438
|
+
advanced_config (Optional[AdvancedGlideClientConfiguration]): Advanced configuration settings for the client,
|
|
439
|
+
see `AdvancedGlideClientConfiguration`.
|
|
318
440
|
"""
|
|
319
441
|
|
|
320
442
|
class PubSubChannelModes(IntEnum):
|
|
321
443
|
"""
|
|
322
444
|
Describes pubsub subsciption modes.
|
|
323
|
-
See https://valkey.io/docs/topics/pubsub/ for more details
|
|
445
|
+
See [valkey.io](https://valkey.io/docs/topics/pubsub/) for more details
|
|
324
446
|
"""
|
|
325
447
|
|
|
326
448
|
Exact = 0
|
|
@@ -362,6 +484,7 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
362
484
|
inflight_requests_limit: Optional[int] = None,
|
|
363
485
|
client_az: Optional[str] = None,
|
|
364
486
|
advanced_config: Optional[AdvancedGlideClientConfiguration] = None,
|
|
487
|
+
lazy_connect: Optional[bool] = None,
|
|
365
488
|
):
|
|
366
489
|
super().__init__(
|
|
367
490
|
addresses=addresses,
|
|
@@ -369,13 +492,14 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
369
492
|
credentials=credentials,
|
|
370
493
|
read_from=read_from,
|
|
371
494
|
request_timeout=request_timeout,
|
|
495
|
+
reconnect_strategy=reconnect_strategy,
|
|
372
496
|
client_name=client_name,
|
|
373
497
|
protocol=protocol,
|
|
374
498
|
inflight_requests_limit=inflight_requests_limit,
|
|
375
499
|
client_az=client_az,
|
|
376
500
|
advanced_config=advanced_config,
|
|
501
|
+
lazy_connect=lazy_connect,
|
|
377
502
|
)
|
|
378
|
-
self.reconnect_strategy = reconnect_strategy
|
|
379
503
|
self.database_id = database_id
|
|
380
504
|
self.pubsub_subscriptions = pubsub_subscriptions
|
|
381
505
|
|
|
@@ -384,14 +508,6 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
384
508
|
) -> ConnectionRequest:
|
|
385
509
|
assert cluster_mode is False
|
|
386
510
|
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
511
|
if self.database_id:
|
|
396
512
|
request.database_id = self.database_id
|
|
397
513
|
|
|
@@ -435,46 +551,65 @@ class AdvancedGlideClusterClientConfiguration(AdvancedBaseClientConfiguration):
|
|
|
435
551
|
Represents the advanced configuration settings for a Glide Cluster client.
|
|
436
552
|
"""
|
|
437
553
|
|
|
438
|
-
def __init__(
|
|
439
|
-
|
|
554
|
+
def __init__(
|
|
555
|
+
self,
|
|
556
|
+
connection_timeout: Optional[int] = None,
|
|
557
|
+
tls_config: Optional[TlsAdvancedConfiguration] = None,
|
|
558
|
+
):
|
|
559
|
+
super().__init__(connection_timeout, tls_config)
|
|
440
560
|
|
|
441
561
|
|
|
442
562
|
class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
443
563
|
"""
|
|
444
564
|
Represents the configuration settings for a Cluster Glide client.
|
|
445
565
|
|
|
446
|
-
|
|
566
|
+
Attributes:
|
|
447
567
|
addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
|
|
448
|
-
|
|
449
|
-
|
|
568
|
+
The list can be partial, as the client will attempt to map out the cluster and find all nodes.
|
|
569
|
+
For example::
|
|
570
|
+
|
|
450
571
|
[
|
|
451
572
|
{address:configuration-endpoint.use1.cache.amazonaws.com, port:6379}
|
|
452
|
-
]
|
|
573
|
+
]
|
|
574
|
+
|
|
453
575
|
use_tls (bool): True if communication with the cluster should use Transport Level Security.
|
|
576
|
+
For advanced tls configuration, please use `AdvancedGlideClusterClientConfiguration`.
|
|
454
577
|
credentials (ServerCredentials): Credentials for authentication process.
|
|
455
578
|
If none are set, the client will not authenticate itself with the server.
|
|
456
579
|
read_from (ReadFrom): If not set, `PRIMARY` will be used.
|
|
457
580
|
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
|
|
459
|
-
|
|
460
|
-
|
|
581
|
+
This duration encompasses sending the request, awaiting for a response from the server, and any required
|
|
582
|
+
reconnection or retries.
|
|
583
|
+
If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not explicitly
|
|
584
|
+
set, a default value of 250 milliseconds will be used.
|
|
585
|
+
reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of
|
|
586
|
+
connection failures.
|
|
587
|
+
If not set, a default backoff strategy will be used.
|
|
588
|
+
client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during
|
|
589
|
+
connection establishment.
|
|
461
590
|
protocol (ProtocolVersion): The version of the RESP protocol to communicate with the server.
|
|
462
591
|
periodic_checks (Union[PeriodicChecksStatus, PeriodicChecksManualInterval]): Configure the periodic topology checks.
|
|
463
592
|
These checks evaluate changes in the cluster's topology, triggering a slot refresh when detected.
|
|
464
593
|
Periodic checks ensure a quick and efficient process by querying a limited number of nodes.
|
|
465
594
|
Defaults to PeriodicChecksStatus.ENABLED_DEFAULT_CONFIGS.
|
|
466
|
-
pubsub_subscriptions (Optional[GlideClusterClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used
|
|
595
|
+
pubsub_subscriptions (Optional[GlideClusterClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used
|
|
596
|
+
for the client.
|
|
467
597
|
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
|
|
469
|
-
|
|
598
|
+
inflight_requests_limit (Optional[int]): The maximum number of concurrent requests allowed to be in-flight
|
|
599
|
+
(sent but not yet completed).
|
|
600
|
+
This limit is used to control the memory usage and prevent the client from overwhelming the server or getting
|
|
601
|
+
stuck in case of a queue backlog.
|
|
470
602
|
If not set, a default value will be used.
|
|
471
603
|
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
|
|
473
|
-
|
|
474
|
-
|
|
604
|
+
If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within
|
|
605
|
+
the specified AZ if exits.
|
|
606
|
+
If ReadFrom strategy is AZAffinityReplicasAndPrimary, this setting ensures that readonly commands are directed to
|
|
607
|
+
nodes (first replicas then primary) within the specified AZ if they exist.
|
|
608
|
+
advanced_config (Optional[AdvancedGlideClusterClientConfiguration]) : Advanced configuration settings for the client,
|
|
609
|
+
see `AdvancedGlideClusterClientConfiguration`.
|
|
475
610
|
|
|
476
611
|
|
|
477
|
-
|
|
612
|
+
Note:
|
|
478
613
|
Currently, the reconnection strategy in cluster mode is not configurable, and exponential backoff
|
|
479
614
|
with fixed values is used.
|
|
480
615
|
"""
|
|
@@ -482,7 +617,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
482
617
|
class PubSubChannelModes(IntEnum):
|
|
483
618
|
"""
|
|
484
619
|
Describes pubsub subsciption modes.
|
|
485
|
-
See https://valkey.io/docs/topics/pubsub/ for more details
|
|
620
|
+
See [valkey.io](https://valkey.io/docs/topics/pubsub/) for more details
|
|
486
621
|
"""
|
|
487
622
|
|
|
488
623
|
Exact = 0
|
|
@@ -518,6 +653,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
518
653
|
credentials: Optional[ServerCredentials] = None,
|
|
519
654
|
read_from: ReadFrom = ReadFrom.PRIMARY,
|
|
520
655
|
request_timeout: Optional[int] = None,
|
|
656
|
+
reconnect_strategy: Optional[BackoffStrategy] = None,
|
|
521
657
|
client_name: Optional[str] = None,
|
|
522
658
|
protocol: ProtocolVersion = ProtocolVersion.RESP3,
|
|
523
659
|
periodic_checks: Union[
|
|
@@ -527,6 +663,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
527
663
|
inflight_requests_limit: Optional[int] = None,
|
|
528
664
|
client_az: Optional[str] = None,
|
|
529
665
|
advanced_config: Optional[AdvancedGlideClusterClientConfiguration] = None,
|
|
666
|
+
lazy_connect: Optional[bool] = None,
|
|
530
667
|
):
|
|
531
668
|
super().__init__(
|
|
532
669
|
addresses=addresses,
|
|
@@ -534,11 +671,13 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
534
671
|
credentials=credentials,
|
|
535
672
|
read_from=read_from,
|
|
536
673
|
request_timeout=request_timeout,
|
|
674
|
+
reconnect_strategy=reconnect_strategy,
|
|
537
675
|
client_name=client_name,
|
|
538
676
|
protocol=protocol,
|
|
539
677
|
inflight_requests_limit=inflight_requests_limit,
|
|
540
678
|
client_az=client_az,
|
|
541
679
|
advanced_config=advanced_config,
|
|
680
|
+
lazy_connect=lazy_connect,
|
|
542
681
|
)
|
|
543
682
|
self.periodic_checks = periodic_checks
|
|
544
683
|
self.pubsub_subscriptions = pubsub_subscriptions
|
|
@@ -577,6 +716,8 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
577
716
|
for channel_pattern in channels_patterns:
|
|
578
717
|
entry.channels_or_patterns.append(str.encode(channel_pattern))
|
|
579
718
|
|
|
719
|
+
if self.lazy_connect is not None:
|
|
720
|
+
request.lazy_connect = self.lazy_connect
|
|
580
721
|
return request
|
|
581
722
|
|
|
582
723
|
def _is_pubsub_configured(self) -> bool:
|
glide/constants.py
CHANGED
|
@@ -34,7 +34,8 @@ TSingleNodeRoute = Union[RandomNode, SlotKeyRoute, SlotIdRoute, ByAddressRoute]
|
|
|
34
34
|
# When specifying legacy path (path doesn't start with `$`), response will be T
|
|
35
35
|
# Otherwise, (when specifying JSONPath), response will be List[Optional[T]].
|
|
36
36
|
#
|
|
37
|
-
# TJsonResponse is designed to handle scenarios where some paths may not contain valid values, especially with JSONPath
|
|
37
|
+
# TJsonResponse is designed to handle scenarios where some paths may not contain valid values, especially with JSONPath
|
|
38
|
+
# targeting multiple paths.
|
|
38
39
|
# In such cases, the response may include None values, represented as `Optional[T]` in the list.
|
|
39
40
|
# This type provides flexibility for commands where a subset of the paths may return None.
|
|
40
41
|
#
|
|
@@ -44,13 +45,15 @@ TJsonResponse = Union[T, List[Optional[T]]]
|
|
|
44
45
|
# When specifying legacy path (path doesn't start with `$`), response will be T
|
|
45
46
|
# Otherwise, (when specifying JSONPath), response will be List[T].
|
|
46
47
|
# This type represents the response format for commands that apply to every path and every type in a JSON document.
|
|
47
|
-
# It covers both singular and multiple paths, ensuring that the command returns valid results for each matched path
|
|
48
|
+
# It covers both singular and multiple paths, ensuring that the command returns valid results for each matched path
|
|
49
|
+
# without None values.
|
|
48
50
|
#
|
|
49
51
|
# TJsonUniversalResponse is considered "universal" because it applies to every matched path and
|
|
50
52
|
# guarantees valid, non-null results across all paths, covering both singular and multiple paths.
|
|
51
53
|
# This type is used for commands that return results from all matched paths, ensuring that each
|
|
52
54
|
# path contains meaningful values without None entries (unless it's part of the commands response).
|
|
53
|
-
# It is typically used in scenarios where each target is expected to yield a valid response. For commands that are valid
|
|
55
|
+
# It is typically used in scenarios where each target is expected to yield a valid response. For commands that are valid
|
|
56
|
+
# for all target types.
|
|
54
57
|
#
|
|
55
58
|
# For more information, see: https://redis.io/docs/data-types/json/path/ .
|
|
56
59
|
TJsonUniversalResponse = Union[T, List[T]]
|
|
@@ -62,7 +65,8 @@ TFunctionListResponse = List[
|
|
|
62
65
|
]
|
|
63
66
|
]
|
|
64
67
|
# Response for function stats command on a single node.
|
|
65
|
-
# The response holds a map with 2 keys: Current running function / script and information about it, and the engines and
|
|
68
|
+
# The response holds a map with 2 keys: Current running function / script and information about it, and the engines and
|
|
69
|
+
# the information about it.
|
|
66
70
|
TFunctionStatsSingleNodeResponse = Mapping[
|
|
67
71
|
bytes,
|
|
68
72
|
Union[
|
|
Binary file
|