summaryrefslogtreecommitdiff
path: root/redis/asyncio/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'redis/asyncio/client.py')
-rw-r--r--redis/asyncio/client.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py
index 9c8caae..c13054b 100644
--- a/redis/asyncio/client.py
+++ b/redis/asyncio/client.py
@@ -24,6 +24,8 @@ from typing import (
cast,
)
+import async_timeout
+
from redis.asyncio.connection import (
Connection,
ConnectionPool,
@@ -754,15 +756,21 @@ class PubSub:
await self.check_health()
- async def try_read():
- if not block:
- if not await conn.can_read(timeout=timeout):
+ if not conn.is_connected:
+ await conn.connect()
+
+ if not block:
+
+ async def read_with_timeout():
+ try:
+ async with async_timeout.timeout(timeout):
+ return await conn.read_response()
+ except asyncio.TimeoutError:
return None
- else:
- await conn.connect()
- return await conn.read_response()
- response = await self._execute(conn, try_read)
+ response = await self._execute(conn, read_with_timeout)
+ else:
+ response = await self._execute(conn, conn.read_response)
if conn.health_check_interval and response == self.health_check_response:
# ignore the health check message as user might not expect it