@@ -591,7 +591,8 @@ def __init__(
591
591
self .retry = retry
592
592
kwargs .update ({"retry" : self .retry })
593
593
else :
594
- kwargs .update ({"retry" : Retry (default_backoff (), 0 )})
594
+ self .retry = Retry (default_backoff (), 0 )
595
+ kwargs ['retry' ] = self .retry
595
596
596
597
self .encoder = Encoder (
597
598
kwargs .get ("encoding" , "utf-8" ),
@@ -775,6 +776,7 @@ def pipeline(self, transaction=None, shard_hint=None):
775
776
read_from_replicas = self .read_from_replicas ,
776
777
reinitialize_steps = self .reinitialize_steps ,
777
778
lock = self ._lock ,
779
+ retry = self .retry ,
778
780
)
779
781
780
782
def lock (
@@ -1794,6 +1796,7 @@ def __init__(
1794
1796
cluster_error_retry_attempts : int = 3 ,
1795
1797
reinitialize_steps : int = 5 ,
1796
1798
lock = None ,
1799
+ retry : Optional ["Retry" ] = None ,
1797
1800
** kwargs ,
1798
1801
):
1799
1802
""" """
@@ -1819,6 +1822,7 @@ def __init__(
1819
1822
if lock is None :
1820
1823
lock = threading .Lock ()
1821
1824
self ._lock = lock
1825
+ self .retry = retry
1822
1826
1823
1827
def __repr__ (self ):
1824
1828
""" """
@@ -1951,8 +1955,9 @@ def send_cluster_commands(
1951
1955
stack ,
1952
1956
raise_on_error = raise_on_error ,
1953
1957
allow_redirections = allow_redirections ,
1958
+ attempts_count = self .cluster_error_retry_attempts - retry_attempts
1954
1959
)
1955
- except (ClusterDownError , ConnectionError ) as e :
1960
+ except (ClusterDownError , ConnectionError , TimeoutError ) as e :
1956
1961
if retry_attempts > 0 :
1957
1962
# Try again with the new cluster setup. All other errors
1958
1963
# should be raised.
@@ -1962,7 +1967,7 @@ def send_cluster_commands(
1962
1967
raise e
1963
1968
1964
1969
def _send_cluster_commands (
1965
- self , stack , raise_on_error = True , allow_redirections = True
1970
+ self , stack , raise_on_error = True , allow_redirections = True , attempts_count = 0
1966
1971
):
1967
1972
"""
1968
1973
Send a bunch of cluster commands to the redis cluster.
@@ -2017,9 +2022,11 @@ def _send_cluster_commands(
2017
2022
redis_node = self .get_redis_connection (node )
2018
2023
try :
2019
2024
connection = get_connection (redis_node , c .args )
2020
- except ConnectionError :
2021
- # Connection retries are being handled in the node's
2022
- # Retry object. Reinitialize the node -> slot table.
2025
+ except (ConnectionError , TimeoutError ) as e :
2026
+ if self .retry and isinstance (e , self .retry ._supported_errors ):
2027
+ backoff = self .retry ._backoff .compute (attempts_count )
2028
+ if backoff > 0 :
2029
+ time .sleep (backoff )
2023
2030
self .nodes_manager .initialize ()
2024
2031
if is_default_node :
2025
2032
self .replace_default_node ()
0 commit comments