11import copy
2- import logging
32import random
43import socket
54import sys
1514from redis .exceptions import (
1615 AskError ,
1716 AuthenticationError ,
18- BusyLoadingError ,
1917 ClusterCrossSlotError ,
2018 ClusterDownError ,
2119 ClusterError ,
3937 str_if_bytes ,
4038)
4139
42- log = logging .getLogger (__name__ )
43-
4440
4541def get_node_name (host : str , port : int ) -> str :
4642 return f"{ host } :{ port } "
@@ -535,7 +531,6 @@ def __init__(
535531 " RedisCluster(startup_nodes=[ClusterNode('localhost', 6379),"
536532 " ClusterNode('localhost', 6378)])"
537533 )
538- log .debug (f"startup_nodes : { startup_nodes } " )
539534 # Update the connection arguments
540535 # Whenever a new connection is established, RedisCluster's on_connect
541536 # method should be run
@@ -666,13 +661,8 @@ def set_default_node(self, node):
666661 :return True if the default node was set, else False
667662 """
668663 if node is None or self .get_node (node_name = node .name ) is None :
669- log .info (
670- "The requested node does not exist in the cluster, so "
671- "the default node was not changed."
672- )
673664 return False
674665 self .nodes_manager .default_node = node
675- log .info (f"Changed the default cluster node to { node } " )
676666 return True
677667
678668 def monitor (self , target_node = None ):
@@ -816,8 +806,6 @@ def _determine_nodes(self, *args, **kwargs):
816806 else :
817807 # get the nodes group for this command if it was predefined
818808 command_flag = self .command_flags .get (command )
819- if command_flag :
820- log .debug (f"Target node/s for { command } : { command_flag } " )
821809 if command_flag == self .__class__ .RANDOM :
822810 # return a random node
823811 return [self .get_random_node ()]
@@ -841,7 +829,6 @@ def _determine_nodes(self, *args, **kwargs):
841829 node = self .nodes_manager .get_node_from_slot (
842830 slot , self .read_from_replicas and command in READ_COMMANDS
843831 )
844- log .debug (f"Target for { args } : slot { slot } " )
845832 return [node ]
846833
847834 def _should_reinitialized (self ):
@@ -1019,7 +1006,7 @@ def execute_command(self, *args, **kwargs):
10191006 res [node .name ] = self ._execute_command (node , * args , ** kwargs )
10201007 # Return the processed result
10211008 return self ._process_result (args [0 ], res , ** kwargs )
1022- except BaseException as e :
1009+ except Exception as e :
10231010 if type (e ) in self .__class__ .ERRORS_ALLOW_RETRY :
10241011 # The nodes and slots cache were reinitialized.
10251012 # Try again with the new cluster setup.
@@ -1059,10 +1046,6 @@ def _execute_command(self, target_node, *args, **kwargs):
10591046 )
10601047 moved = False
10611048
1062- log .debug (
1063- f"Executing command { command } on target node: "
1064- f"{ target_node .server_type } { target_node .name } "
1065- )
10661049 redis_node = self .get_redis_connection (target_node )
10671050 connection = get_connection (redis_node , * args , ** kwargs )
10681051 if asking :
@@ -1077,12 +1060,9 @@ def _execute_command(self, target_node, *args, **kwargs):
10771060 response , ** kwargs
10781061 )
10791062 return response
1080-
1081- except (RedisClusterException , BusyLoadingError , AuthenticationError ) as e :
1082- log .exception (type (e ))
1063+ except AuthenticationError :
10831064 raise
10841065 except (ConnectionError , TimeoutError ) as e :
1085- log .exception (type (e ))
10861066 # ConnectionError can also be raised if we couldn't get a
10871067 # connection from the pool before timing out, so check that
10881068 # this is an actual connection before attempting to disconnect.
@@ -1101,7 +1081,7 @@ def _execute_command(self, target_node, *args, **kwargs):
11011081 # and try again with the new setup
11021082 target_node .redis_connection = None
11031083 self .nodes_manager .initialize ()
1104- raise
1084+ raise e
11051085 except MovedError as e :
11061086 # First, we will try to patch the slots/nodes cache with the
11071087 # redirected node output and try again. If MovedError exceeds
@@ -1111,7 +1091,6 @@ def _execute_command(self, target_node, *args, **kwargs):
11111091 # the same client object is shared between multiple threads. To
11121092 # reduce the frequency you can set this variable in the
11131093 # RedisCluster constructor.
1114- log .exception ("MovedError" )
11151094 self .reinitialize_counter += 1
11161095 if self ._should_reinitialized ():
11171096 self .nodes_manager .initialize ()
@@ -1121,29 +1100,21 @@ def _execute_command(self, target_node, *args, **kwargs):
11211100 self .nodes_manager .update_moved_exception (e )
11221101 moved = True
11231102 except TryAgainError :
1124- log .exception ("TryAgainError" )
1125-
11261103 if ttl < self .RedisClusterRequestTTL / 2 :
11271104 time .sleep (0.05 )
11281105 except AskError as e :
1129- log .exception ("AskError" )
1130-
11311106 redirect_addr = get_node_name (host = e .host , port = e .port )
11321107 asking = True
11331108 except ClusterDownError as e :
1134- log .exception ("ClusterDownError" )
11351109 # ClusterDownError can occur during a failover and to get
11361110 # self-healed, we will try to reinitialize the cluster layout
11371111 # and retry executing the command
11381112 time .sleep (0.25 )
11391113 self .nodes_manager .initialize ()
11401114 raise e
1141- except ResponseError as e :
1142- message = e .__str__ ()
1143- log .exception (f"ResponseError: { message } " )
1144- raise e
1145- except BaseException as e :
1146- log .exception ("BaseException" )
1115+ except ResponseError :
1116+ raise
1117+ except Exception as e :
11471118 if connection :
11481119 connection .disconnect ()
11491120 raise e
@@ -1280,11 +1251,6 @@ def get_node(self, host=None, port=None, node_name=None):
12801251 elif node_name :
12811252 return self .nodes_cache .get (node_name )
12821253 else :
1283- log .error (
1284- "get_node requires one of the following: "
1285- "1. node name "
1286- "2. host and port"
1287- )
12881254 return None
12891255
12901256 def update_moved_exception (self , exception ):
@@ -1432,7 +1398,6 @@ def initialize(self):
14321398 :startup_nodes:
14331399 Responsible for discovering other nodes in the cluster
14341400 """
1435- log .debug ("Initializing the nodes' topology of the cluster" )
14361401 self .reset ()
14371402 tmp_nodes_cache = {}
14381403 tmp_slots = {}
@@ -1460,17 +1425,9 @@ def initialize(self):
14601425 )
14611426 cluster_slots = str_if_bytes (r .execute_command ("CLUSTER SLOTS" ))
14621427 startup_nodes_reachable = True
1463- except (ConnectionError , TimeoutError ) as e :
1464- msg = e .__str__
1465- log .exception (
1466- "An exception occurred while trying to"
1467- " initialize the cluster using the seed node"
1468- f" { startup_node .name } :\n { msg } "
1469- )
1428+ except (ConnectionError , TimeoutError ):
14701429 continue
14711430 except ResponseError as e :
1472- log .exception ('ReseponseError sending "cluster slots" to redis server' )
1473-
14741431 # Isn't a cluster connection, so it won't parse these
14751432 # exceptions automatically
14761433 message = e .__str__ ()
@@ -2042,12 +1999,6 @@ def _send_cluster_commands(
20421999 # If a lot of commands have failed, we'll be setting the
20432000 # flag to rebuild the slots table from scratch.
20442001 # So MOVED errors should correct themselves fairly quickly.
2045- log .exception (
2046- f"An exception occurred during pipeline execution. "
2047- f"args: { attempt [- 1 ].args } , "
2048- f"error: { type (attempt [- 1 ].result ).__name__ } "
2049- f"{ str (attempt [- 1 ].result )} "
2050- )
20512002 self .reinitialize_counter += 1
20522003 if self ._should_reinitialized ():
20532004 self .nodes_manager .initialize ()
0 commit comments