From 7577492076e27da66ba32abfea6f22c852e553df Mon Sep 17 00:00:00 2001 From: tzongw Date: Fri, 6 Jun 2025 23:35:23 +0800 Subject: [PATCH] TransactionStrategy reset: UNWATCH only when status is watching --- redis/asyncio/cluster.py | 9 +++++---- redis/cluster.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/redis/asyncio/cluster.py b/redis/asyncio/cluster.py index 1f34e03011..5823d2f935 100644 --- a/redis/asyncio/cluster.py +++ b/redis/asyncio/cluster.py @@ -2350,10 +2350,11 @@ async def reset(self): # watching something if self._transaction_connection: try: - # call this manually since our unwatch or - # immediate_execute_command methods can call reset() - await self._transaction_connection.send_command("UNWATCH") - await self._transaction_connection.read_response() + if self._watching: + # call this manually since our unwatch or + # immediate_execute_command methods can call reset() + await self._transaction_connection.send_command("UNWATCH") + await self._transaction_connection.read_response() # we can safely return the connection to the pool here since we're # sure we're no longer WATCHing anything self._transaction_node.release(self._transaction_connection) diff --git a/redis/cluster.py b/redis/cluster.py index baa85ae122..5ea1caa609 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -3290,10 +3290,11 @@ def reset(self): # watching something if self._transaction_connection: try: - # call this manually since our unwatch or - # immediate_execute_command methods can call reset() - self._transaction_connection.send_command("UNWATCH") - self._transaction_connection.read_response() + if self._watching: + # call this manually since our unwatch or + # immediate_execute_command methods can call reset() + self._transaction_connection.send_command("UNWATCH") + self._transaction_connection.read_response() # we can safely return the connection to the pool here since we're # sure we're no longer WATCHing anything node = self._nodes_manager.find_connection_owner(