@@ -589,6 +589,14 @@ def _execute_command(self, *args, **kwargs):
589
589
ttl = int (self .RedisClusterRequestTTL )
590
590
connection_error_retry_counter = 0
591
591
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
+
592
600
while ttl > 0 :
593
601
ttl -= 1
594
602
connection = None
@@ -630,7 +638,7 @@ def _execute_command(self, *args, **kwargs):
630
638
connection .send_command (* args )
631
639
return self .parse_response (connection , command , ** kwargs )
632
640
except SlotNotCoveredError as e :
633
- log . exception ("SlotNotCoveredError" )
641
+ log_exception ("SlotNotCoveredError" , e )
634
642
635
643
# In some cases during failover to a replica is happening
636
644
# a slot sometimes is not covered by the cluster layout and
@@ -644,8 +652,8 @@ def _execute_command(self, *args, **kwargs):
644
652
except (RedisClusterException , BusyLoadingError ):
645
653
log .exception ("RedisClusterException || BusyLoadingError" )
646
654
raise
647
- except ConnectionError :
648
- log . exception ("ConnectionError" )
655
+ except ConnectionError as e :
656
+ log_exception ("ConnectionError" , e )
649
657
650
658
# ConnectionError can also be raised if we couldn't get a connection
651
659
# from the pool before timing out, so check that this is an actual
@@ -670,8 +678,8 @@ def _execute_command(self, *args, **kwargs):
670
678
self .connection_pool .nodes .increment_reinitialize_counter (
671
679
count = self .connection_pool .nodes .reinitialize_steps ,
672
680
)
673
- except TimeoutError :
674
- log . exception ("TimeoutError" )
681
+ except TimeoutError as e :
682
+ log_exception ("TimeoutError" , e )
675
683
connection .disconnect ()
676
684
677
685
if ttl < self .RedisClusterRequestTTL / 2 :
@@ -692,20 +700,20 @@ def _execute_command(self, *args, **kwargs):
692
700
# This counter will increase faster when the same client object
693
701
# is shared between multiple threads. To reduce the frequency you
694
702
# can set the variable 'reinitialize_steps' in the constructor.
695
- log . exception ("MovedError" )
703
+ log_exception ("MovedError" , e )
696
704
697
705
self .refresh_table_asap = True
698
706
self .connection_pool .nodes .increment_reinitialize_counter ()
699
707
700
708
node = self .connection_pool .nodes .set_node (e .host , e .port , server_type = 'master' )
701
709
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 )
704
712
705
713
if ttl < self .RedisClusterRequestTTL / 2 :
706
714
time .sleep (0.05 )
707
715
except AskError as e :
708
- log . exception ("AskError" )
716
+ log_exception ("AskError" , e )
709
717
710
718
redirect_addr , asking = "{0}:{1}" .format (e .host , e .port ), True
711
719
except BaseException as e :
0 commit comments