Skip to content

Commit 68172e0

Browse files
committed
feat: Add handling for MULTI block execution with AUTH response check and error handling
1 parent e4f3db6 commit 68172e0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

redis/connection.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,29 @@ def on_connect(self):
412412
self.read_response()
413413
self._parser.set_invalidation_push_handler(self._cache_invalidation_process)
414414

415+
# execute the MULTI block
416+
try:
417+
self.send_command('EXEC')
418+
responses = self._read_exec_responses()
419+
# check AUTH response if AUTH command was sent
420+
if auth_command_response:
421+
# First response should be for AUTH command
422+
auth_response = responses[0]
423+
if b'ERR' in auth_response:
424+
raise AuthenticationError(
425+
"Authentication failed: %s" % auth_response)
426+
responses = responses[1:] # Remove AUTH response from the list
427+
428+
self._handle_responses(responses, auth_args)
429+
except (TimeoutError, AuthenticationError, ConnectionError) as e:
430+
if not self.retry_on_timeout:
431+
raise e
432+
except Exception as e:
433+
if str(e) == "Invalid Username or Password":
434+
raise AuthenticationError("Invalid Username or Password") from e
435+
else:
436+
raise AuthenticationError() from e
437+
415438
def disconnect(self, *args):
416439
"Disconnects from the Redis server"
417440
self._parser.on_disconnect()

0 commit comments

Comments
 (0)