8
8
from abc import abstractmethod
9
9
from itertools import chain
10
10
from queue import Empty , Full , LifoQueue
11
- from typing import Any , Callable , Dict , List , Literal , Optional , Type , TypeVar , Union
11
+ from typing import (
12
+ Any ,
13
+ Callable ,
14
+ Dict ,
15
+ Iterable ,
16
+ List ,
17
+ Literal ,
18
+ Optional ,
19
+ Type ,
20
+ TypeVar ,
21
+ Union ,
22
+ )
12
23
from urllib .parse import parse_qs , unquote , urlparse
13
24
14
25
from redis .cache import (
@@ -311,7 +322,7 @@ def __init__(
311
322
socket_timeout : Optional [float ] = None ,
312
323
socket_connect_timeout : Optional [float ] = None ,
313
324
retry_on_timeout : bool = False ,
314
- retry_on_error = SENTINEL ,
325
+ retry_on_error : Union [ Iterable [ Type [ Exception ]], object ] = SENTINEL ,
315
326
encoding : str = "utf-8" ,
316
327
encoding_errors : str = "strict" ,
317
328
decode_responses : bool = False ,
@@ -367,19 +378,22 @@ def __init__(
367
378
self .socket_connect_timeout = socket_connect_timeout
368
379
self .retry_on_timeout = retry_on_timeout
369
380
if retry_on_error is SENTINEL :
370
- retry_on_error = []
381
+ retry_on_errors_list = []
382
+ else :
383
+ retry_on_errors_list = list (retry_on_error )
371
384
if retry_on_timeout :
372
385
# Add TimeoutError to the errors list to retry on
373
- retry_on_error .append (TimeoutError )
374
- self .retry_on_error = retry_on_error
375
- if retry or retry_on_error :
386
+ retry_on_errors_list .append (TimeoutError )
387
+ self .retry_on_error = retry_on_errors_list
388
+ if retry or self . retry_on_error :
376
389
if retry is None :
377
390
self .retry = Retry (NoBackoff (), 1 )
378
391
else :
379
392
# deep-copy the Retry object as it is mutable
380
393
self .retry = copy .deepcopy (retry )
381
- # Update the retry's supported errors with the specified errors
382
- self .retry .update_supported_errors (retry_on_error )
394
+ if self .retry_on_error :
395
+ # Update the retry's supported errors with the specified errors
396
+ self .retry .update_supported_errors (self .retry_on_error )
383
397
else :
384
398
self .retry = Retry (NoBackoff (), 0 )
385
399
self .health_check_interval = health_check_interval
@@ -1912,6 +1926,9 @@ def should_update_connection(
1912
1926
address_type_to_match : Literal ["connected" , "configured" ] = "connected" ,
1913
1927
matching_address : Optional [str ] = None ,
1914
1928
) -> bool :
1929
+ """
1930
+ Check if the connection should be updated based on the matching address.
1931
+ """
1915
1932
if address_type_to_match == "connected" :
1916
1933
if matching_address and conn .getpeername () != matching_address :
1917
1934
return False
@@ -1964,6 +1981,7 @@ def update_connections_settings(
1964
1981
:param address_type_to_match: The type of address to match.
1965
1982
:param reset_host_address: Whether to reset the host address to the original address.
1966
1983
:param reset_relax_timeout: Whether to reset the relax timeout to the original timeout.
1984
+ :param include_free_connections: Whether to include free/available connections.
1967
1985
"""
1968
1986
for conn in self ._in_use_connections :
1969
1987
if self .should_update_connection (
@@ -2016,6 +2034,7 @@ def update_active_connections_for_reconnect(
2016
2034
2017
2035
:param tmp_host_address: The temporary host address to use for the connection.
2018
2036
:param tmp_relax_timeout: The relax timeout to use for the connection.
2037
+ :param moving_address_src: The address of the node that is being moved.
2019
2038
"""
2020
2039
for conn in self ._in_use_connections :
2021
2040
if self .should_update_connection (conn , "connected" , moving_address_src ):
@@ -2035,8 +2054,9 @@ def disconnect_and_reconfigure_free_connections(
2035
2054
2036
2055
When this method is called the pool will already be locked, so getting the pool lock inside is not needed.
2037
2056
2038
- :param orig_host_address: The temporary host address to use for the connection.
2039
- :param orig_relax_timeout: The relax timeout to use for the connection.
2057
+ :param tmp_host_address: The temporary host address to use for the connection.
2058
+ :param tmp_relax_timeout: The relax timeout to use for the connection.
2059
+ :param moving_address_src: The address of the node that is being moved.
2040
2060
"""
2041
2061
2042
2062
for conn in self ._available_connections :
@@ -2361,6 +2381,7 @@ def update_active_connections_for_reconnect(
2361
2381
2362
2382
:param tmp_host_address: The temporary host address to use for the connection.
2363
2383
:param tmp_relax_timeout: The relax timeout to use for the connection.
2384
+ :param moving_address_src: The address of the node that is being moved.
2364
2385
"""
2365
2386
with self ._lock :
2366
2387
connections_in_queue = {conn for conn in self .pool .queue if conn }
@@ -2386,6 +2407,7 @@ def disconnect_and_reconfigure_free_connections(
2386
2407
2387
2408
:param tmp_host_address: The temporary host address to use for the connection.
2388
2409
:param tmp_relax_timeout: The relax timeout to use for the connection.
2410
+ :param moving_address_src: The address of the node that is being moved.
2389
2411
"""
2390
2412
existing_connections = self .pool .queue
2391
2413
0 commit comments