Skip to content

Commit ef3f086

Browse files
authored
Fix async (#2673)
1 parent 5acbde3 commit ef3f086

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

redis/asyncio/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,13 +1227,9 @@ async def immediate_execute_command(self, *args, **options):
12271227
command_name, self.shard_hint
12281228
)
12291229
self.connection = conn
1230-
try:
1231-
return await asyncio.shield(
1232-
self._try_send_command_parse_response(conn, *args, **options)
1233-
)
1234-
except asyncio.CancelledError:
1235-
await conn.disconnect()
1236-
raise
1230+
return await asyncio.shield(
1231+
self._try_send_command_parse_response(conn, *args, **options)
1232+
)
12371233

12381234
def pipeline_execute_command(self, *args, **options):
12391235
"""

tests/test_asyncio/test_cwe_404.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,35 @@ async def test_standalone_pipeline(delay):
8888
addr=("localhost", 5380), redis_addr=("localhost", 6379), delay=delay * 2
8989
)
9090
await dp.start()
91-
async with Redis(host="localhost", port=5380) as r:
92-
await r.set("foo", "foo")
93-
await r.set("bar", "bar")
91+
for b in [True, False]:
92+
async with Redis(host="localhost", port=5380, single_connection_client=b) as r:
93+
await r.set("foo", "foo")
94+
await r.set("bar", "bar")
9495

95-
pipe = r.pipeline()
96+
pipe = r.pipeline()
9697

97-
pipe2 = r.pipeline()
98-
pipe2.get("bar")
99-
pipe2.ping()
100-
pipe2.get("foo")
98+
pipe2 = r.pipeline()
99+
pipe2.get("bar")
100+
pipe2.ping()
101+
pipe2.get("foo")
101102

102-
t = asyncio.create_task(pipe.get("foo").execute())
103-
await asyncio.sleep(delay)
104-
t.cancel()
103+
t = asyncio.create_task(pipe.get("foo").execute())
104+
await asyncio.sleep(delay)
105+
t.cancel()
105106

106-
pipe.get("bar")
107-
pipe.ping()
108-
pipe.get("foo")
109-
pipe.reset()
107+
pipe.get("bar")
108+
pipe.ping()
109+
pipe.get("foo")
110+
pipe.reset()
110111

111-
assert await pipe.execute() is None
112+
assert await pipe.execute() is None
112113

113-
# validating that the pipeline can be used as it could previously
114-
pipe.get("bar")
115-
pipe.ping()
116-
pipe.get("foo")
117-
assert await pipe.execute() == [b"bar", True, b"foo"]
118-
assert await pipe2.execute() == [b"bar", True, b"foo"]
114+
# validating that the pipeline can be used as it could previously
115+
pipe.get("bar")
116+
pipe.ping()
117+
pipe.get("foo")
118+
assert await pipe.execute() == [b"bar", True, b"foo"]
119+
assert await pipe2.execute() == [b"bar", True, b"foo"]
119120

120121
await dp.stop()
121122

0 commit comments

Comments
 (0)