Skip to content

Commit

Permalink
Merge pull request #443 from laixintao/reissue-with-password
Browse files Browse the repository at this point in the history
bugfix: when being redirected in cluster mode, should still auth with password.
  • Loading branch information
laixintao authored Sep 14, 2022
2 parents caeabae + d3a3af8 commit 2c1bd35
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions iredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ def execute_by_connection(self, connection, command_name, *args, **options):
last_error = e
retry_times -= 1
need_refresh_connection = True
except redis.exceptions.ExecAbortError:
config.transaction = False
raise
except ResponseError as e:
response_message = str(e)
if response_message.startswith("MOVED"):
Expand All @@ -299,9 +302,6 @@ def execute_by_connection(self, connection, command_name, *args, **options):
)
raise e

except redis.exceptions.ExecAbortError:
config.transaction = False
raise
except KeyboardInterrupt:
logger.warning("received KeyboardInterrupt... rebuild connection...")
connection.disconnect()
Expand All @@ -313,7 +313,8 @@ def execute_by_connection(self, connection, command_name, *args, **options):
return None
else:
return response
raise last_error
if last_error:
raise last_error

def reissue_with_redirect(self, response, *args, **kwargs):
"""
Expand All @@ -323,13 +324,21 @@ def reissue_with_redirect(self, response, *args, **kwargs):
This feature is not supported for unix socket connection.
"""
# Redis Cluster only supports database zero.
_, slot, ip_port = response.split(" ")
_, _, ip_port = response.split(" ")
ip, port = ip_port.split(":")
port = int(port)

print(response, file=sys.stderr)

connection = self.create_connection(ip, port)
connection = self.create_connection(
ip,
port,
username=self.username,
password=self.password,
path=self.path,
scheme=self.scheme,
client_name=self.client_name,
)
# if user sets dsn for dest node
# use username and password from dsn settings
if config.alias_dsn:
Expand Down

0 comments on commit 2c1bd35

Please sign in to comment.