@@ -576,7 +576,8 @@ def __init__(
576
576
self .retry = retry
577
577
kwargs .update ({"retry" : self .retry })
578
578
else :
579
- kwargs .update ({"retry" : Retry (default_backoff (), 0 )})
579
+ self .retry = Retry (default_backoff (), 0 )
580
+ kwargs ['retry' ] = self .retry
580
581
581
582
self .encoder = Encoder (
582
583
kwargs .get ("encoding" , "utf-8" ),
@@ -759,6 +760,7 @@ def pipeline(self, transaction=None, shard_hint=None):
759
760
read_from_replicas = self .read_from_replicas ,
760
761
reinitialize_steps = self .reinitialize_steps ,
761
762
lock = self ._lock ,
763
+ retry = self .retry ,
762
764
)
763
765
764
766
def lock (
@@ -1764,6 +1766,7 @@ def __init__(
1764
1766
cluster_error_retry_attempts : int = 3 ,
1765
1767
reinitialize_steps : int = 5 ,
1766
1768
lock = None ,
1769
+ retry : Optional ["Retry" ] = None ,
1767
1770
** kwargs ,
1768
1771
):
1769
1772
""" """
@@ -1789,6 +1792,7 @@ def __init__(
1789
1792
if lock is None :
1790
1793
lock = threading .Lock ()
1791
1794
self ._lock = lock
1795
+ self .retry = retry
1792
1796
1793
1797
def __repr__ (self ):
1794
1798
""" """
@@ -1921,8 +1925,9 @@ def send_cluster_commands(
1921
1925
stack ,
1922
1926
raise_on_error = raise_on_error ,
1923
1927
allow_redirections = allow_redirections ,
1928
+ attempts_count = self .cluster_error_retry_attempts - retry_attempts
1924
1929
)
1925
- except (ClusterDownError , ConnectionError ) as e :
1930
+ except (ClusterDownError , ConnectionError , TimeoutError ) as e :
1926
1931
if retry_attempts > 0 :
1927
1932
# Try again with the new cluster setup. All other errors
1928
1933
# should be raised.
@@ -1932,7 +1937,7 @@ def send_cluster_commands(
1932
1937
raise e
1933
1938
1934
1939
def _send_cluster_commands (
1935
- self , stack , raise_on_error = True , allow_redirections = True
1940
+ self , stack , raise_on_error = True , allow_redirections = True , attempts_count = 0
1936
1941
):
1937
1942
"""
1938
1943
Send a bunch of cluster commands to the redis cluster.
@@ -1987,9 +1992,11 @@ def _send_cluster_commands(
1987
1992
redis_node = self .get_redis_connection (node )
1988
1993
try :
1989
1994
connection = get_connection (redis_node , c .args )
1990
- except ConnectionError :
1991
- # Connection retries are being handled in the node's
1992
- # Retry object. Reinitialize the node -> slot table.
1995
+ except (ConnectionError , TimeoutError ) as e :
1996
+ if self .retry and isinstance (e , self .retry ._supported_errors ):
1997
+ backoff = self .retry ._backoff .compute (attempts_count )
1998
+ if backoff > 0 :
1999
+ time .sleep (backoff )
1993
2000
self .nodes_manager .initialize ()
1994
2001
if is_default_node :
1995
2002
self .replace_default_node ()
0 commit comments