@@ -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 :
@@ -683,7 +691,7 @@ def _execute_command(self, *args, **kwargs):
683691 if command in READ_COMMANDS :
684692 try_random_node = True
685693 except ClusterDownError as e :
686- log .exception ("ClusterDownError" )
694+ log .exception ("ClusterDownError" , e )
687695
688696 self .connection_pool .disconnect ()
689697 self .connection_pool .reset ()
@@ -696,20 +704,20 @@ def _execute_command(self, *args, **kwargs):
696704 # This counter will increase faster when the same client object
697705 # is shared between multiple threads. To reduce the frequency you
698706 # can set the variable 'reinitialize_steps' in the constructor.
699- log . exception ("MovedError" )
707+ log_exception ("MovedError" , e )
700708
701709 self .refresh_table_asap = True
702710 self .connection_pool .nodes .increment_reinitialize_counter ()
703711
704712 node = self .connection_pool .nodes .set_node (e .host , e .port , server_type = 'master' )
705713 self .connection_pool .nodes .slots [e .slot_id ][0 ] = node
706- except TryAgainError :
707- log . exception ("TryAgainError" )
714+ except TryAgainError as e :
715+ log_exception ("TryAgainError" , e )
708716
709717 if ttl < self .RedisClusterRequestTTL / 2 :
710718 time .sleep (0.05 )
711719 except AskError as e :
712- log . exception ("AskError" )
720+ log_exception ("AskError" , e )
713721
714722 redirect_addr , asking = "{0}:{1}" .format (e .host , e .port ), True
715723 except BaseException as e :
0 commit comments