Skip to content

Commit f020748

Browse files
committed
don't use can_read in pubsub
1 parent 5cc0704 commit f020748

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,11 @@ async def read_response(self, disable_decoding: bool = False):
934934
raise ConnectionError(
935935
f"Error while reading from {self.host}:{self.port} : {e.args}"
936936
)
937-
except BaseException:
937+
except asyncio.CancelledError:
938+
# need this check for 3.7, where CancelledError
939+
# is subclass of Exception, not BaseException
940+
raise
941+
except Exception:
938942
await self.disconnect()
939943
raise
940944

0 commit comments

Comments
 (0)