@@ -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 (
@@ -1796,6 +1798,7 @@ def __init__(
1796
1798
cluster_error_retry_attempts : int = 3 ,
1797
1799
reinitialize_steps : int = 5 ,
1798
1800
lock = None ,
1801
+ retry : Optional ["Retry" ] = None ,
1799
1802
** kwargs ,
1800
1803
):
1801
1804
""" """
@@ -1821,6 +1824,7 @@ def __init__(
1821
1824
if lock is None :
1822
1825
lock = threading .Lock ()
1823
1826
self ._lock = lock
1827
+ self .retry = retry
1824
1828
1825
1829
def __repr__ (self ):
1826
1830
""" """
@@ -1953,8 +1957,9 @@ def send_cluster_commands(
1953
1957
stack ,
1954
1958
raise_on_error = raise_on_error ,
1955
1959
allow_redirections = allow_redirections ,
1960
+ attempts_count = self .cluster_error_retry_attempts - retry_attempts ,
1956
1961
)
1957
- except (ClusterDownError , ConnectionError ) as e :
1962
+ except (ClusterDownError , ConnectionError , TimeoutError ) as e :
1958
1963
if retry_attempts > 0 :
1959
1964
# Try again with the new cluster setup. All other errors
1960
1965
# should be raised.
@@ -1964,7 +1969,7 @@ def send_cluster_commands(
1964
1969
raise e
1965
1970
1966
1971
def _send_cluster_commands (
1967
- self , stack , raise_on_error = True , allow_redirections = True
1972
+ self , stack , raise_on_error = True , allow_redirections = True , attempts_count = 0
1968
1973
):
1969
1974
"""
1970
1975
Send a bunch of cluster commands to the redis cluster.
@@ -2019,9 +2024,11 @@ def _send_cluster_commands(
2019
2024
redis_node = self .get_redis_connection (node )
2020
2025
try :
2021
2026
connection = get_connection (redis_node , c .args )
2022
- except ConnectionError :
2023
- # Connection retries are being handled in the node's
2024
- # Retry object. Reinitialize the node -> slot table.
2027
+ except (ConnectionError , TimeoutError ) as e :
2028
+ if self .retry and isinstance (e , self .retry ._supported_errors ):
2029
+ backoff = self .retry ._backoff .compute (attempts_count )
2030
+ if backoff > 0 :
2031
+ time .sleep (backoff )
2025
2032
self .nodes_manager .initialize ()
2026
2033
if is_default_node :
2027
2034
self .replace_default_node ()
0 commit comments