@@ -589,6 +589,14 @@ def _execute_command(self, *args, **kwargs):
589589 ttl = int (self .RedisClusterRequestTTL )
590590 connection_error_retry_counter = 0
591591
592+ def log_exception (message , exception ):
593+ if ttl == 1 :
594+ # This is the last attempt before we run out of TTL, so log the full exception.
595+ log .exception (message )
596+ else :
597+ # We are going to retry, and therefore may yet succeed, so just log a warning.
598+ log .warning (message + str (exception ))
599+
592600 while ttl > 0 :
593601 ttl -= 1
594602 connection = None
@@ -630,7 +638,7 @@ def _execute_command(self, *args, **kwargs):
630638 connection .send_command (* args )
631639 return self .parse_response (connection , command , ** kwargs )
632640 except SlotNotCoveredError as e :
633- log . exception ("SlotNotCoveredError" )
641+ log_exception ("SlotNotCoveredError" , e )
634642
635643 # In some cases during failover to a replica is happening
636644 # a slot sometimes is not covered by the cluster layout and
@@ -644,8 +652,8 @@ def _execute_command(self, *args, **kwargs):
644652 except (RedisClusterException , BusyLoadingError ):
645653 log .exception ("RedisClusterException || BusyLoadingError" )
646654 raise
647- except ConnectionError :
648- log . exception ("ConnectionError" )
655+ except ConnectionError as e :
656+ log_exception ("ConnectionError" , e )
649657
650658 # ConnectionError can also be raised if we couldn't get a connection
651659 # from the pool before timing out, so check that this is an actual
@@ -670,8 +678,8 @@ def _execute_command(self, *args, **kwargs):
670678 self .connection_pool .nodes .increment_reinitialize_counter (
671679 count = self .connection_pool .nodes .reinitialize_steps ,
672680 )
673- except TimeoutError :
674- log . exception ("TimeoutError" )
681+ except TimeoutError as e :
682+ log_exception ("TimeoutError" , e )
675683 connection .disconnect ()
676684
677685 if ttl < self .RedisClusterRequestTTL / 2 :
@@ -692,20 +700,20 @@ def _execute_command(self, *args, **kwargs):
692700 # This counter will increase faster when the same client object
693701 # is shared between multiple threads. To reduce the frequency you
694702 # can set the variable 'reinitialize_steps' in the constructor.
695- log . exception ("MovedError" )
703+ log_exception ("MovedError" , e )
696704
697705 self .refresh_table_asap = True
698706 self .connection_pool .nodes .increment_reinitialize_counter ()
699707
700708 node = self .connection_pool .nodes .set_node (e .host , e .port , server_type = 'master' )
701709 self .connection_pool .nodes .slots [e .slot_id ][0 ] = node
702- except TryAgainError :
703- log . exception ("TryAgainError" )
710+ except TryAgainError as e :
711+ log_exception ("TryAgainError" , e )
704712
705713 if ttl < self .RedisClusterRequestTTL / 2 :
706714 time .sleep (0.05 )
707715 except AskError as e :
708- log . exception ("AskError" )
716+ log_exception ("AskError" , e )
709717
710718 redirect_addr , asking = "{0}:{1}" .format (e .host , e .port ), True
711719 except BaseException as e :
0 commit comments