valkey-glide 2.0.0rc7__cp310-cp310-macosx_11_0_arm64.whl → 2.1.0rc1__cp310-cp310-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 +103 -107
- glide/async_commands/cluster_commands.py +83 -101
- glide/async_commands/core.py +554 -424
- glide/async_commands/{server_modules/ft.py → ft.py} +8 -7
- glide/async_commands/{server_modules/glide_json.py → glide_json.py} +15 -92
- glide/async_commands/standalone_commands.py +18 -17
- glide/glide.cpython-310-darwin.so +0 -0
- glide/glide.pyi +26 -1
- glide/glide_client.py +70 -45
- glide/logger.py +33 -21
- glide/opentelemetry.py +185 -0
- glide_shared/__init__.py +326 -0
- {glide/async_commands → glide_shared/commands}/batch.py +411 -18
- glide_shared/commands/batch_options.py +261 -0
- glide_shared/commands/core_options.py +407 -0
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +3 -3
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +4 -2
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +4 -4
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +4 -2
- {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +4 -4
- glide_shared/commands/server_modules/json_options.py +93 -0
- {glide/async_commands → glide_shared/commands}/sorted_set.py +2 -2
- {glide/async_commands → glide_shared/commands}/stream.py +1 -1
- {glide → glide_shared}/config.py +120 -32
- {glide → glide_shared}/constants.py +3 -3
- {glide → glide_shared}/exceptions.py +27 -1
- glide_shared/protobuf/command_request_pb2.py +54 -0
- glide_shared/protobuf/connection_request_pb2.py +52 -0
- {glide → glide_shared}/protobuf/response_pb2.py +6 -6
- {glide → glide_shared}/routes.py +29 -15
- valkey_glide-2.1.0rc1.dist-info/METADATA +210 -0
- valkey_glide-2.1.0rc1.dist-info/RECORD +39 -0
- glide/protobuf/command_request_pb2.py +0 -54
- glide/protobuf/command_request_pb2.pyi +0 -1187
- glide/protobuf/connection_request_pb2.py +0 -54
- glide/protobuf/connection_request_pb2.pyi +0 -320
- glide/protobuf/response_pb2.pyi +0 -100
- valkey_glide-2.0.0rc7.dist-info/METADATA +0 -144
- valkey_glide-2.0.0rc7.dist-info/RECORD +0 -37
- /glide/py.typed → /glide_shared/commands/__init__.py +0 -0
- {glide/async_commands → glide_shared/commands}/bitmap.py +0 -0
- {glide/async_commands → glide_shared/commands}/command_args.py +0 -0
- {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
- {glide → glide_shared}/protobuf_codec.py +0 -0
- {valkey_glide-2.0.0rc7.dist-info → valkey_glide-2.1.0rc1.dist-info}/WHEEL +0 -0
{glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py
RENAMED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
from enum import Enum
|
|
3
3
|
from typing import List, Optional, Union, cast
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from glide_shared.commands.server_modules.ft_options.ft_aggregate_options import (
|
|
6
6
|
FtAggregateOptions,
|
|
7
7
|
)
|
|
8
|
-
from
|
|
8
|
+
from glide_shared.commands.server_modules.ft_options.ft_constants import (
|
|
9
9
|
FtProfileKeywords,
|
|
10
10
|
)
|
|
11
|
-
from
|
|
11
|
+
from glide_shared.commands.server_modules.ft_options.ft_search_options import (
|
|
12
12
|
FtSearchOptions,
|
|
13
13
|
)
|
|
14
|
-
from
|
|
14
|
+
from glide_shared.constants import TEncodable
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class QueryType(Enum):
|
{glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py
RENAMED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
from typing import List, Mapping, Optional
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
|
|
5
|
+
from glide_shared.commands.server_modules.ft_options.ft_constants import (
|
|
6
|
+
FtSearchKeywords,
|
|
7
|
+
)
|
|
8
|
+
from glide_shared.constants import TEncodable
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
class FtSearchLimit:
|
|
@@ -22,14 +22,14 @@ Examples:
|
|
|
22
22
|
|
|
23
23
|
from typing import List, Optional, Union
|
|
24
24
|
|
|
25
|
-
from
|
|
26
|
-
from
|
|
27
|
-
from
|
|
25
|
+
from glide_shared.commands.batch import TBatch
|
|
26
|
+
from glide_shared.commands.core_options import ConditionalChange
|
|
27
|
+
from glide_shared.commands.server_modules.json_options import (
|
|
28
28
|
JsonArrIndexOptions,
|
|
29
29
|
JsonArrPopOptions,
|
|
30
30
|
JsonGetOptions,
|
|
31
31
|
)
|
|
32
|
-
from
|
|
32
|
+
from glide_shared.constants import TEncodable
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
def set(
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
from glide_shared.constants import TEncodable
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class JsonArrIndexOptions:
|
|
9
|
+
"""
|
|
10
|
+
Options for the `JSON.ARRINDEX` command.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
start (int): The inclusive start index from which the search begins. Defaults to None.
|
|
14
|
+
end (Optional[int]): The exclusive end index where the search stops. Defaults to None.
|
|
15
|
+
|
|
16
|
+
Note:
|
|
17
|
+
- If `start` is greater than `end`, the command returns `-1` to indicate that the value was not found.
|
|
18
|
+
- Indices that exceed the array bounds are automatically adjusted to the nearest valid position.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, start: int, end: Optional[int] = None):
|
|
22
|
+
self.start = start
|
|
23
|
+
self.end = end
|
|
24
|
+
|
|
25
|
+
def to_args(self) -> List[str]:
|
|
26
|
+
"""
|
|
27
|
+
Get the options as a list of arguments for the JSON.ARRINDEX command.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
List[str]: A list containing the start and end indices if specified.
|
|
31
|
+
"""
|
|
32
|
+
args = [str(self.start)]
|
|
33
|
+
if self.end is not None:
|
|
34
|
+
args.append(str(self.end))
|
|
35
|
+
return args
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class JsonArrPopOptions:
|
|
39
|
+
"""
|
|
40
|
+
Options for the JSON.ARRPOP command.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
path (TEncodable): The path within the JSON document.
|
|
44
|
+
index (Optional[int]): The index of the element to pop. If not specified, will pop the last element.
|
|
45
|
+
Out of boundary indexes are rounded to their respective array boundaries. Defaults to None.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def __init__(self, path: TEncodable, index: Optional[int] = None):
|
|
49
|
+
self.path = path
|
|
50
|
+
self.index = index
|
|
51
|
+
|
|
52
|
+
def to_args(self) -> List[TEncodable]:
|
|
53
|
+
"""
|
|
54
|
+
Get the options as a list of arguments for the `JSON.ARRPOP` command.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
List[TEncodable]: A list containing the path and, if specified, the index.
|
|
58
|
+
"""
|
|
59
|
+
args = [self.path]
|
|
60
|
+
if self.index is not None:
|
|
61
|
+
args.append(str(self.index))
|
|
62
|
+
return args
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class JsonGetOptions:
|
|
66
|
+
"""
|
|
67
|
+
Represents options for formatting JSON data, to be used in the [JSON.GET](https://valkey.io/commands/json.get/) command.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
indent (Optional[str]): Sets an indentation string for nested levels. Defaults to None.
|
|
71
|
+
newline (Optional[str]): Sets a string that's printed at the end of each line. Defaults to None.
|
|
72
|
+
space (Optional[str]): Sets a string that's put between a key and a value. Defaults to None.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
def __init__(
|
|
76
|
+
self,
|
|
77
|
+
indent: Optional[str] = None,
|
|
78
|
+
newline: Optional[str] = None,
|
|
79
|
+
space: Optional[str] = None,
|
|
80
|
+
):
|
|
81
|
+
self.indent = indent
|
|
82
|
+
self.new_line = newline
|
|
83
|
+
self.space = space
|
|
84
|
+
|
|
85
|
+
def get_options(self) -> List[str]:
|
|
86
|
+
args = []
|
|
87
|
+
if self.indent:
|
|
88
|
+
args.extend(["INDENT", self.indent])
|
|
89
|
+
if self.new_line:
|
|
90
|
+
args.extend(["NEWLINE", self.new_line])
|
|
91
|
+
if self.space:
|
|
92
|
+
args.extend(["SPACE", self.space])
|
|
93
|
+
return args
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
from enum import Enum
|
|
4
4
|
from typing import List, Optional, Tuple, Union, cast
|
|
5
5
|
|
|
6
|
-
from
|
|
7
|
-
from
|
|
6
|
+
from glide_shared.commands.command_args import Limit, OrderBy
|
|
7
|
+
from glide_shared.constants import TEncodable
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class InfBound(Enum):
|
{glide → glide_shared}/config.py
RENAMED
|
@@ -6,12 +6,18 @@ from dataclasses import dataclass
|
|
|
6
6
|
from enum import Enum, IntEnum
|
|
7
7
|
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
from
|
|
9
|
+
from glide_shared.commands.core_options import PubSubMsg
|
|
10
|
+
from glide_shared.exceptions import ConfigurationError
|
|
11
|
+
from glide_shared.protobuf.connection_request_pb2 import (
|
|
12
|
+
ConnectionRequest,
|
|
13
|
+
)
|
|
14
|
+
from glide_shared.protobuf.connection_request_pb2 import (
|
|
15
|
+
ProtocolVersion as SentProtocolVersion,
|
|
16
|
+
)
|
|
17
|
+
from glide_shared.protobuf.connection_request_pb2 import ReadFrom as ProtobufReadFrom
|
|
18
|
+
from glide_shared.protobuf.connection_request_pb2 import (
|
|
19
|
+
TlsMode,
|
|
20
|
+
)
|
|
15
21
|
|
|
16
22
|
|
|
17
23
|
class NodeAddress:
|
|
@@ -73,7 +79,7 @@ class BackoffStrategy:
|
|
|
73
79
|
"""
|
|
74
80
|
Represents the strategy used to determine how and when to reconnect, in case of connection failures.
|
|
75
81
|
The time between attempts grows exponentially, to the formula rand(0 .. factor * (exponentBase ^ N)), where N
|
|
76
|
-
is the number of failed attempts.
|
|
82
|
+
is the number of failed attempts, and rand(...) applies a jitter of up to jitter_percent% to introduce randomness and reduce retry storms.
|
|
77
83
|
Once the maximum value is reached, that will remain the time between retry attempts until a reconnect attempt is
|
|
78
84
|
successful.
|
|
79
85
|
The client will attempt to reconnect indefinitely.
|
|
@@ -83,6 +89,7 @@ class BackoffStrategy:
|
|
|
83
89
|
where the time between retries increases. Once the retries have reached the maximum value, the time between
|
|
84
90
|
retries will remain constant until a reconnect attempt is succesful.
|
|
85
91
|
factor (int): The multiplier that will be applied to the waiting time between each retry.
|
|
92
|
+
This value is specified in milliseconds.
|
|
86
93
|
exponent_base (int): The exponent base configured for the strategy.
|
|
87
94
|
jitter_percent (Optional[int]): The Jitter percent on the calculated duration. If not set, a default value will be used.
|
|
88
95
|
"""
|
|
@@ -147,25 +154,66 @@ class PeriodicChecksStatus(Enum):
|
|
|
147
154
|
"""
|
|
148
155
|
|
|
149
156
|
|
|
157
|
+
class TlsAdvancedConfiguration:
|
|
158
|
+
"""
|
|
159
|
+
Represents advanced TLS configuration settings.
|
|
160
|
+
|
|
161
|
+
Attributes:
|
|
162
|
+
use_insecure_tls (Optional[bool]): Whether to bypass TLS certificate verification.
|
|
163
|
+
|
|
164
|
+
- When set to True, the client skips certificate validation.
|
|
165
|
+
This is useful when connecting to servers or clusters using self-signed certificates,
|
|
166
|
+
or when DNS entries (e.g., CNAMEs) don't match certificate hostnames.
|
|
167
|
+
|
|
168
|
+
- This setting is typically used in development or testing environments. **It is
|
|
169
|
+
strongly discouraged in production**, as it introduces security risks such as man-in-the-middle attacks.
|
|
170
|
+
|
|
171
|
+
- Only valid if TLS is already enabled in the base client configuration.
|
|
172
|
+
Enabling it without TLS will result in a `ConfigurationError`.
|
|
173
|
+
|
|
174
|
+
- Default: False (verification is enforced).
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
def __init__(self, use_insecure_tls: Optional[bool] = None):
|
|
178
|
+
self.use_insecure_tls = use_insecure_tls
|
|
179
|
+
|
|
180
|
+
|
|
150
181
|
class AdvancedBaseClientConfiguration:
|
|
151
182
|
"""
|
|
152
183
|
Represents the advanced configuration settings for a base Glide client.
|
|
153
184
|
|
|
154
185
|
Attributes:
|
|
155
186
|
connection_timeout (Optional[int]): The duration in milliseconds to wait for a TCP/TLS connection to complete.
|
|
156
|
-
This applies both during initial client creation and any
|
|
187
|
+
This applies both during initial client creation and any reconnection that may occur during request processing.
|
|
157
188
|
**Note**: A high connection timeout may lead to prolonged blocking of the entire command pipeline.
|
|
158
|
-
If not explicitly set, a default value of
|
|
189
|
+
If not explicitly set, a default value of 2000 milliseconds will be used.
|
|
190
|
+
tls_config (Optional[TlsAdvancedConfiguration]): The advanced TLS configuration settings.
|
|
191
|
+
This allows for more granular control of TLS behavior, such as enabling an insecure mode
|
|
192
|
+
that bypasses certificate validation.
|
|
159
193
|
"""
|
|
160
194
|
|
|
161
|
-
def __init__(
|
|
195
|
+
def __init__(
|
|
196
|
+
self,
|
|
197
|
+
connection_timeout: Optional[int] = None,
|
|
198
|
+
tls_config: Optional[TlsAdvancedConfiguration] = None,
|
|
199
|
+
):
|
|
162
200
|
self.connection_timeout = connection_timeout
|
|
201
|
+
self.tls_config = tls_config
|
|
163
202
|
|
|
164
203
|
def _create_a_protobuf_conn_request(
|
|
165
204
|
self, request: ConnectionRequest
|
|
166
205
|
) -> ConnectionRequest:
|
|
167
206
|
if self.connection_timeout:
|
|
168
207
|
request.connection_timeout = self.connection_timeout
|
|
208
|
+
|
|
209
|
+
if self.tls_config and self.tls_config.use_insecure_tls:
|
|
210
|
+
if request.tls_mode == TlsMode.SecureTls:
|
|
211
|
+
request.tls_mode = TlsMode.InsecureTls
|
|
212
|
+
elif request.tls_mode == TlsMode.NoTls:
|
|
213
|
+
raise ConfigurationError(
|
|
214
|
+
"use_insecure_tls cannot be enabled when use_tls is disabled."
|
|
215
|
+
)
|
|
216
|
+
|
|
169
217
|
return request
|
|
170
218
|
|
|
171
219
|
|
|
@@ -182,19 +230,20 @@ class BaseClientConfiguration:
|
|
|
182
230
|
For example::
|
|
183
231
|
|
|
184
232
|
[
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
]
|
|
233
|
+
NodeAddress("sample-address-0001.use1.cache.amazonaws.com", 6379),
|
|
234
|
+
NodeAddress("sample-address-0002.use1.cache.amazonaws.com", 6379)
|
|
235
|
+
]
|
|
188
236
|
|
|
189
237
|
use_tls (bool): True if communication with the cluster should use Transport Level Security.
|
|
190
|
-
Should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail
|
|
238
|
+
Should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail.
|
|
239
|
+
For advanced tls configuration, please use `AdvancedBaseClientConfiguration`.
|
|
191
240
|
credentials (ServerCredentials): Credentials for authentication process.
|
|
192
241
|
If none are set, the client will not authenticate itself with the server.
|
|
193
242
|
read_from (ReadFrom): If not set, `PRIMARY` will be used.
|
|
194
243
|
request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to
|
|
195
244
|
complete.
|
|
196
245
|
This duration encompasses sending the request, awaiting for a response from the server, and any required
|
|
197
|
-
|
|
246
|
+
reconnection or retries.
|
|
198
247
|
If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not
|
|
199
248
|
explicitly set, a default value of 250 milliseconds will be used.
|
|
200
249
|
reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of
|
|
@@ -214,6 +263,25 @@ class BaseClientConfiguration:
|
|
|
214
263
|
If ReadFrom strategy is AZAffinityReplicasAndPrimary, this setting ensures that readonly commands are directed
|
|
215
264
|
to nodes (first replicas then primary) within the specified AZ if they exist.
|
|
216
265
|
advanced_config (Optional[AdvancedBaseClientConfiguration]): Advanced configuration settings for the client.
|
|
266
|
+
|
|
267
|
+
lazy_connect (Optional[bool]): Enables lazy connection mode, where physical connections to the server(s)
|
|
268
|
+
are deferred until the first command is sent. This can reduce startup latency and allow for client
|
|
269
|
+
creation in disconnected environments.
|
|
270
|
+
|
|
271
|
+
When set to `True`, the client will not attempt to connect to the specified nodes during
|
|
272
|
+
initialization. Instead, connections will be established only when a command is actually executed.
|
|
273
|
+
|
|
274
|
+
Note that the first command executed with lazy connections may experience additional latency
|
|
275
|
+
as it needs to establish the connection first. During this initial connection, the standard
|
|
276
|
+
request timeout does not apply yet - instead, the connection establishment is governed by
|
|
277
|
+
`AdvancedBaseClientConfiguration.connection_timeout`. The request timeout (`request_timeout`)
|
|
278
|
+
only begins counting after the connection has been successfully established. This behavior
|
|
279
|
+
can effectively increase the total time needed for the first command to complete.
|
|
280
|
+
|
|
281
|
+
This setting applies to both standalone and cluster modes. Note that if an operation is
|
|
282
|
+
attempted and connection fails (e.g., unreachable nodes), errors will surface at that point.
|
|
283
|
+
|
|
284
|
+
If not set, connections are established immediately during client creation (equivalent to `False`).
|
|
217
285
|
"""
|
|
218
286
|
|
|
219
287
|
def __init__(
|
|
@@ -229,6 +297,7 @@ class BaseClientConfiguration:
|
|
|
229
297
|
inflight_requests_limit: Optional[int] = None,
|
|
230
298
|
client_az: Optional[str] = None,
|
|
231
299
|
advanced_config: Optional[AdvancedBaseClientConfiguration] = None,
|
|
300
|
+
lazy_connect: Optional[bool] = None,
|
|
232
301
|
):
|
|
233
302
|
self.addresses = addresses
|
|
234
303
|
self.use_tls = use_tls
|
|
@@ -241,6 +310,7 @@ class BaseClientConfiguration:
|
|
|
241
310
|
self.inflight_requests_limit = inflight_requests_limit
|
|
242
311
|
self.client_az = client_az
|
|
243
312
|
self.advanced_config = advanced_config
|
|
313
|
+
self.lazy_connect = lazy_connect
|
|
244
314
|
|
|
245
315
|
if read_from == ReadFrom.AZ_AFFINITY and not client_az:
|
|
246
316
|
raise ValueError(
|
|
@@ -301,6 +371,8 @@ class BaseClientConfiguration:
|
|
|
301
371
|
if self.advanced_config:
|
|
302
372
|
self.advanced_config._create_a_protobuf_conn_request(request)
|
|
303
373
|
|
|
374
|
+
if self.lazy_connect is not None:
|
|
375
|
+
request.lazy_connect = self.lazy_connect
|
|
304
376
|
return request
|
|
305
377
|
|
|
306
378
|
def _is_pubsub_configured(self) -> bool:
|
|
@@ -308,7 +380,7 @@ class BaseClientConfiguration:
|
|
|
308
380
|
|
|
309
381
|
def _get_pubsub_callback_and_context(
|
|
310
382
|
self,
|
|
311
|
-
) -> Tuple[Optional[Callable[[
|
|
383
|
+
) -> Tuple[Optional[Callable[[PubSubMsg, Any], None]], Any]:
|
|
312
384
|
return None, None
|
|
313
385
|
|
|
314
386
|
|
|
@@ -317,9 +389,13 @@ class AdvancedGlideClientConfiguration(AdvancedBaseClientConfiguration):
|
|
|
317
389
|
Represents the advanced configuration settings for a Standalone Glide client.
|
|
318
390
|
"""
|
|
319
391
|
|
|
320
|
-
def __init__(
|
|
392
|
+
def __init__(
|
|
393
|
+
self,
|
|
394
|
+
connection_timeout: Optional[int] = None,
|
|
395
|
+
tls_config: Optional[TlsAdvancedConfiguration] = None,
|
|
396
|
+
):
|
|
321
397
|
|
|
322
|
-
super().__init__(connection_timeout)
|
|
398
|
+
super().__init__(connection_timeout, tls_config)
|
|
323
399
|
|
|
324
400
|
|
|
325
401
|
class GlideClientConfiguration(BaseClientConfiguration):
|
|
@@ -328,21 +404,22 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
328
404
|
|
|
329
405
|
Attributes:
|
|
330
406
|
addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
|
|
331
|
-
|
|
407
|
+
Only nodes whose addresses were provided will be used by the client.
|
|
332
408
|
For example::
|
|
333
409
|
|
|
334
410
|
[
|
|
335
|
-
|
|
336
|
-
|
|
411
|
+
NodeAddress("sample-address-0001.use1.cache.amazonaws.com", 6379),
|
|
412
|
+
NodeAddress("sample-address-0002.use1.cache.amazonaws.com", 6379)
|
|
337
413
|
]
|
|
338
414
|
|
|
339
415
|
use_tls (bool): True if communication with the cluster should use Transport Level Security.
|
|
416
|
+
Please use `AdvancedGlideClusterClientConfiguration`.
|
|
340
417
|
credentials (ServerCredentials): Credentials for authentication process.
|
|
341
418
|
If none are set, the client will not authenticate itself with the server.
|
|
342
419
|
read_from (ReadFrom): If not set, `PRIMARY` will be used.
|
|
343
420
|
request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete.
|
|
344
421
|
This duration encompasses sending the request, awaiting for a response from the server, and any required
|
|
345
|
-
|
|
422
|
+
reconnection or retries.
|
|
346
423
|
If the specified timeout is exceeded for a pending request, it will result in a timeout error.
|
|
347
424
|
If not explicitly set, a default value of 250 milliseconds will be used.
|
|
348
425
|
reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of
|
|
@@ -387,7 +464,7 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
387
464
|
Attributes:
|
|
388
465
|
channels_and_patterns (Dict[GlideClientConfiguration.PubSubChannelModes, Set[str]]):
|
|
389
466
|
Channels and patterns by modes.
|
|
390
|
-
callback (Optional[Callable[[
|
|
467
|
+
callback (Optional[Callable[[PubSubMsg, Any], None]]):
|
|
391
468
|
Optional callback to accept the incomming messages.
|
|
392
469
|
context (Any):
|
|
393
470
|
Arbitrary context to pass to the callback.
|
|
@@ -396,7 +473,7 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
396
473
|
channels_and_patterns: Dict[
|
|
397
474
|
GlideClientConfiguration.PubSubChannelModes, Set[str]
|
|
398
475
|
]
|
|
399
|
-
callback: Optional[Callable[[
|
|
476
|
+
callback: Optional[Callable[[PubSubMsg, Any], None]]
|
|
400
477
|
context: Any
|
|
401
478
|
|
|
402
479
|
def __init__(
|
|
@@ -414,6 +491,7 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
414
491
|
inflight_requests_limit: Optional[int] = None,
|
|
415
492
|
client_az: Optional[str] = None,
|
|
416
493
|
advanced_config: Optional[AdvancedGlideClientConfiguration] = None,
|
|
494
|
+
lazy_connect: Optional[bool] = None,
|
|
417
495
|
):
|
|
418
496
|
super().__init__(
|
|
419
497
|
addresses=addresses,
|
|
@@ -427,6 +505,7 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
427
505
|
inflight_requests_limit=inflight_requests_limit,
|
|
428
506
|
client_az=client_az,
|
|
429
507
|
advanced_config=advanced_config,
|
|
508
|
+
lazy_connect=lazy_connect,
|
|
430
509
|
)
|
|
431
510
|
self.database_id = database_id
|
|
432
511
|
self.pubsub_subscriptions = pubsub_subscriptions
|
|
@@ -468,7 +547,7 @@ class GlideClientConfiguration(BaseClientConfiguration):
|
|
|
468
547
|
|
|
469
548
|
def _get_pubsub_callback_and_context(
|
|
470
549
|
self,
|
|
471
|
-
) -> Tuple[Optional[Callable[[
|
|
550
|
+
) -> Tuple[Optional[Callable[[PubSubMsg, Any], None]], Any]:
|
|
472
551
|
if self.pubsub_subscriptions:
|
|
473
552
|
return self.pubsub_subscriptions.callback, self.pubsub_subscriptions.context
|
|
474
553
|
return None, None
|
|
@@ -479,8 +558,12 @@ class AdvancedGlideClusterClientConfiguration(AdvancedBaseClientConfiguration):
|
|
|
479
558
|
Represents the advanced configuration settings for a Glide Cluster client.
|
|
480
559
|
"""
|
|
481
560
|
|
|
482
|
-
def __init__(
|
|
483
|
-
|
|
561
|
+
def __init__(
|
|
562
|
+
self,
|
|
563
|
+
connection_timeout: Optional[int] = None,
|
|
564
|
+
tls_config: Optional[TlsAdvancedConfiguration] = None,
|
|
565
|
+
):
|
|
566
|
+
super().__init__(connection_timeout, tls_config)
|
|
484
567
|
|
|
485
568
|
|
|
486
569
|
class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
@@ -493,16 +576,17 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
493
576
|
For example::
|
|
494
577
|
|
|
495
578
|
[
|
|
496
|
-
|
|
579
|
+
NodeAddress("sample-address-0001.use1.cache.amazonaws.com", 6379),
|
|
497
580
|
]
|
|
498
581
|
|
|
499
582
|
use_tls (bool): True if communication with the cluster should use Transport Level Security.
|
|
583
|
+
For advanced tls configuration, please use `AdvancedGlideClusterClientConfiguration`.
|
|
500
584
|
credentials (ServerCredentials): Credentials for authentication process.
|
|
501
585
|
If none are set, the client will not authenticate itself with the server.
|
|
502
586
|
read_from (ReadFrom): If not set, `PRIMARY` will be used.
|
|
503
587
|
request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete.
|
|
504
588
|
This duration encompasses sending the request, awaiting for a response from the server, and any required
|
|
505
|
-
|
|
589
|
+
reconnection or retries.
|
|
506
590
|
If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not explicitly
|
|
507
591
|
set, a default value of 250 milliseconds will be used.
|
|
508
592
|
reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of
|
|
@@ -557,7 +641,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
557
641
|
Attributes:
|
|
558
642
|
channels_and_patterns (Dict[GlideClusterClientConfiguration.PubSubChannelModes, Set[str]]):
|
|
559
643
|
Channels and patterns by modes.
|
|
560
|
-
callback (Optional[Callable[[
|
|
644
|
+
callback (Optional[Callable[[PubSubMsg, Any], None]]):
|
|
561
645
|
Optional callback to accept the incoming messages.
|
|
562
646
|
context (Any):
|
|
563
647
|
Arbitrary context to pass to the callback.
|
|
@@ -566,7 +650,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
566
650
|
channels_and_patterns: Dict[
|
|
567
651
|
GlideClusterClientConfiguration.PubSubChannelModes, Set[str]
|
|
568
652
|
]
|
|
569
|
-
callback: Optional[Callable[[
|
|
653
|
+
callback: Optional[Callable[[PubSubMsg, Any], None]]
|
|
570
654
|
context: Any
|
|
571
655
|
|
|
572
656
|
def __init__(
|
|
@@ -586,6 +670,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
586
670
|
inflight_requests_limit: Optional[int] = None,
|
|
587
671
|
client_az: Optional[str] = None,
|
|
588
672
|
advanced_config: Optional[AdvancedGlideClusterClientConfiguration] = None,
|
|
673
|
+
lazy_connect: Optional[bool] = None,
|
|
589
674
|
):
|
|
590
675
|
super().__init__(
|
|
591
676
|
addresses=addresses,
|
|
@@ -599,6 +684,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
599
684
|
inflight_requests_limit=inflight_requests_limit,
|
|
600
685
|
client_az=client_az,
|
|
601
686
|
advanced_config=advanced_config,
|
|
687
|
+
lazy_connect=lazy_connect,
|
|
602
688
|
)
|
|
603
689
|
self.periodic_checks = periodic_checks
|
|
604
690
|
self.pubsub_subscriptions = pubsub_subscriptions
|
|
@@ -637,6 +723,8 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
637
723
|
for channel_pattern in channels_patterns:
|
|
638
724
|
entry.channels_or_patterns.append(str.encode(channel_pattern))
|
|
639
725
|
|
|
726
|
+
if self.lazy_connect is not None:
|
|
727
|
+
request.lazy_connect = self.lazy_connect
|
|
640
728
|
return request
|
|
641
729
|
|
|
642
730
|
def _is_pubsub_configured(self) -> bool:
|
|
@@ -644,7 +732,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration):
|
|
|
644
732
|
|
|
645
733
|
def _get_pubsub_callback_and_context(
|
|
646
734
|
self,
|
|
647
|
-
) -> Tuple[Optional[Callable[[
|
|
735
|
+
) -> Tuple[Optional[Callable[[PubSubMsg, Any], None]], Any]:
|
|
648
736
|
if self.pubsub_subscriptions:
|
|
649
737
|
return self.pubsub_subscriptions.callback, self.pubsub_subscriptions.context
|
|
650
738
|
return None, None
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from typing import Any, Dict, List, Literal, Mapping, Optional, Set, TypeVar, Union
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
from
|
|
7
|
-
from
|
|
5
|
+
from glide_shared.protobuf.command_request_pb2 import CommandRequest
|
|
6
|
+
from glide_shared.protobuf.connection_request_pb2 import ConnectionRequest
|
|
7
|
+
from glide_shared.routes import ByAddressRoute, RandomNode, SlotIdRoute, SlotKeyRoute
|
|
8
8
|
|
|
9
9
|
OK: str = "OK"
|
|
10
10
|
DEFAULT_READ_BYTES_SIZE: int = pow(2, 16)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
2
|
|
|
3
|
-
from typing import Optional
|
|
3
|
+
from typing import Optional, Type
|
|
4
|
+
|
|
5
|
+
from glide_shared.protobuf.response_pb2 import RequestErrorType
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
class GlideError(Exception):
|
|
@@ -60,3 +62,27 @@ class ConfigurationError(RequestError):
|
|
|
60
62
|
"""
|
|
61
63
|
Errors that are thrown when a request cannot be completed in current configuration settings.
|
|
62
64
|
"""
|
|
65
|
+
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class LoggerError(GlideError):
|
|
70
|
+
"""
|
|
71
|
+
Errors that are thrown when the logger has an error initializing.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_request_error_class(
|
|
78
|
+
error_type: Optional[RequestErrorType.ValueType],
|
|
79
|
+
) -> Type[RequestError]:
|
|
80
|
+
if error_type == RequestErrorType.Disconnect:
|
|
81
|
+
return ConnectionError
|
|
82
|
+
if error_type == RequestErrorType.ExecAbort:
|
|
83
|
+
return ExecAbortError
|
|
84
|
+
if error_type == RequestErrorType.Timeout:
|
|
85
|
+
return TimeoutError
|
|
86
|
+
if error_type == RequestErrorType.Unspecified:
|
|
87
|
+
return RequestError
|
|
88
|
+
return RequestError
|