Skip to content

Commit e20f354

Browse files
authored
Fix bug with async pipeline and cluster fails with some commands (#3402)
* Fix bug with async pipeline fails with some commands * Codestyl changes * Remove keys option in cluster context
1 parent aa22225 commit e20f354

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

Diff for: redis/asyncio/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,10 @@ async def _execute_transaction( # noqa: C901
14231423
if not isinstance(r, Exception):
14241424
args, options = cmd
14251425
command_name = args[0]
1426+
1427+
# Remove keys entry, it needs only for cache.
1428+
options.pop("keys", None)
1429+
14261430
if command_name in self.response_callbacks:
14271431
r = self.response_callbacks[command_name](r, **options)
14281432
if inspect.isawaitable(r):

Diff for: redis/cluster.py

+4
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,10 @@ def _execute_command(self, target_node, *args, **kwargs):
11631163
asking = False
11641164
connection.send_command(*args, **kwargs)
11651165
response = redis_node.parse_response(connection, command, **kwargs)
1166+
1167+
# Remove keys entry, it needs only for cache.
1168+
kwargs.pop("keys", None)
1169+
11661170
if command in self.cluster_response_callbacks:
11671171
response = self.cluster_response_callbacks[command](
11681172
response, **kwargs

Diff for: tests/test_asyncio/test_pipeline.py

+10
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,13 @@ async def test_pipeline_discard(self, r):
417417
response = await pipe.execute()
418418
assert response[0]
419419
assert await r.get("foo") == b"bar"
420+
421+
@pytest.mark.onlynoncluster
422+
async def test_send_set_commands_over_async_pipeline(self, r: redis.asyncio.Redis):
423+
pipe = r.pipeline()
424+
pipe.hset("hash:1", "foo", "bar")
425+
pipe.hset("hash:1", "bar", "foo")
426+
pipe.hset("hash:1", "baz", "bar")
427+
pipe.hgetall("hash:1")
428+
resp = await pipe.execute()
429+
assert resp == [1, 1, 1, {b"bar": b"foo", b"baz": b"bar", b"foo": b"bar"}]

Diff for: tests/test_pipeline.py

+10
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,13 @@ def test_pipeline_discard(self, r):
412412
response = pipe.execute()
413413
assert response[0]
414414
assert r.get("foo") == b"bar"
415+
416+
@pytest.mark.onlynoncluster
417+
def test_send_set_commands_over_pipeline(self, r: redis.Redis):
418+
pipe = r.pipeline()
419+
pipe.hset("hash:1", "foo", "bar")
420+
pipe.hset("hash:1", "bar", "foo")
421+
pipe.hset("hash:1", "baz", "bar")
422+
pipe.hgetall("hash:1")
423+
resp = pipe.execute()
424+
assert resp == [1, 1, 1, {b"bar": b"foo", b"baz": b"bar", b"foo": b"bar"}]

0 commit comments

Comments
 (0)