Skip to content

Commit 4bd3656

Browse files
committed
Fixing async cluster pipeline execution when client is created with cluster_error_retry_attempts=0 (redis#3545)
1 parent 6c7acbd commit 4bd3656

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

redis/asyncio/cluster.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,29 +1531,28 @@ async def execute(
15311531
return []
15321532

15331533
try:
1534-
for _ in range(self._client.cluster_error_retry_attempts):
1535-
if self._client._initialize:
1536-
await self._client.initialize()
1537-
1534+
retry_attempts = self._client.cluster_error_retry_attempts
1535+
while True:
15381536
try:
1537+
if self._client._initialize:
1538+
await self._client.initialize()
15391539
return await self._execute(
15401540
self._client,
15411541
self._command_stack,
15421542
raise_on_error=raise_on_error,
15431543
allow_redirections=allow_redirections,
15441544
)
1545-
except BaseException as e:
1546-
if type(e) in self.__class__.ERRORS_ALLOW_RETRY:
1547-
# Try again with the new cluster setup.
1548-
exception = e
1545+
1546+
except self.__class__.ERRORS_ALLOW_RETRY as e:
1547+
if retry_attempts > 0:
1548+
# Try again with the new cluster setup. All other errors
1549+
# should be raised.
1550+
retry_attempts -= 1
15491551
await self._client.aclose()
15501552
await asyncio.sleep(0.25)
15511553
else:
15521554
# All other errors should be raised.
1553-
raise
1554-
1555-
# If it fails the configured number of times then raise an exception
1556-
raise exception
1555+
raise e
15571556
finally:
15581557
self._command_stack = []
15591558

tests/test_asyncio/test_cluster.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,17 @@ async def test_redis_cluster_pipeline(self, r: RedisCluster) -> None:
26942694
)
26952695
assert result == [True, b"1", 1, {b"F": b"V"}, True, True, b"2", b"3", 1, 1, 1]
26962696

2697+
async def test_cluster_pipeline_execution_zero_cluster_err_retries(
2698+
self, r: RedisCluster
2699+
) -> None:
2700+
"""
2701+
Test that we can run successfully cluster pipeline execute at least once when
2702+
cluster_error_retry_attempts is set to 0
2703+
"""
2704+
r.cluster_error_retry_attempts = 0
2705+
result = await r.pipeline().set("A", 1).get("A").delete("A").execute()
2706+
assert result == [True, b"1", 1]
2707+
26972708
async def test_multi_key_operation_with_a_single_slot(
26982709
self, r: RedisCluster
26992710
) -> None:
@@ -2754,7 +2765,7 @@ async def parse_response(
27542765
await pipe.get(key).execute()
27552766
assert (
27562767
node.parse_response.await_count
2757-
== 3 * r.cluster_error_retry_attempts - 2
2768+
== 3 * r.cluster_error_retry_attempts + 1
27582769
)
27592770

27602771
async def test_connection_error_not_raised(self, r: RedisCluster) -> None:

0 commit comments

Comments
 (0)