Skip to content

Commit f2401bf

Browse files
committed
don't use can_read in pubsub
1 parent ced739b commit f2401bf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

redis/asyncio/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
cast,
2525
)
2626

27+
import async_timeout
28+
2729
from redis.asyncio.connection import (
2830
Connection,
2931
ConnectionPool,
@@ -755,12 +757,16 @@ async def parse_response(self, block: bool = True, timeout: float = 0):
755757
await self.check_health()
756758

757759
async def try_read():
760+
if not conn.is_connected:
761+
await conn.connect()
758762
if not block:
759-
if not await conn.can_read(timeout=timeout):
763+
try:
764+
async with async_timeout.timeout(timeout):
765+
return await conn.read_response()
766+
except asyncio.TimeoutError:
760767
return None
761768
else:
762-
await conn.connect()
763-
return await conn.read_response()
769+
return await conn.read_response()
764770

765771
response = await self._execute(conn, try_read)
766772

redis/asyncio/connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ async def read_response(self, disable_decoding: bool = False):
941941
raise ConnectionError(
942942
f"Error while reading from {self.host}:{self.port} : {e.args}"
943943
)
944+
except asyncio.CancelledError:
945+
# need this check for 3.7, where CancelledError
946+
# is subclass of Exception, not BaseException
947+
raise
944948
except Exception:
945949
await self.disconnect()
946950
raise

0 commit comments

Comments
 (0)