diff options
author | Kristján Valur Jónsson <sweskman@gmail.com> | 2022-09-29 11:56:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-29 14:56:50 +0300 |
commit | f014dc3a5d76935914c6e2975e66da44f2e6263b (patch) | |
tree | 465591eb372ccea9d210710d2f0b1760f9ef288d /redis/asyncio/client.py | |
parent | 652ca790b0bbaefa78278ddf57074316a3fb21bd (diff) | |
download | redis-py-f014dc3a5d76935914c6e2975e66da44f2e6263b.tar.gz |
Dev/no can read (#2360)
* make can_read() destructive for simplicity, and rename the method.
Remove timeout argument, always timeout immediately.
* don't use can_read in pubsub
* connection.connect() now has its own retry, don't need it inside a retry loop
Diffstat (limited to 'redis/asyncio/client.py')
-rw-r--r-- | redis/asyncio/client.py | 22 |
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 |