summaryrefslogtreecommitdiff
path: root/redis/asyncio/client.py
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2022-07-27 16:21:25 +0000
committerGitHub <noreply@github.com>2022-07-27 19:21:25 +0300
commitf9f9d06c9951f8536bf9321dcebc96759eae03e0 (patch)
treea290e2d7bc10a28fe67c0ff34ff3a55903fa4261 /redis/asyncio/client.py
parent48f5aca5bb2ed389819b1730f116150f1f0b476d (diff)
downloadredis-py-f9f9d06c9951f8536bf9321dcebc96759eae03e0.tar.gz
automatically reconnect pubsub when reading messages in blocking mode (#2281)
* optimistic default info on test sessionstart. Makes test discovery work, even without a redis connection. * Add unittests verifying that (non-async) PubSub will automatically reconnect * Add tests for asyncio pubsub subsciription auto-reconnect * automatically connect for blocking reads (asyncio) * fix automatic connect on blocking pubsub read (non-async) * lint & format * Perform `connect()` call in PubSub code rather than `read_response`.
Diffstat (limited to 'redis/asyncio/client.py')
-rw-r--r--redis/asyncio/client.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py
index 3d59016..9c8caae 100644
--- a/redis/asyncio/client.py
+++ b/redis/asyncio/client.py
@@ -754,9 +754,15 @@ class PubSub:
await self.check_health()
- if not block and not await self._execute(conn, conn.can_read, timeout=timeout):
- return None
- response = await self._execute(conn, conn.read_response)
+ async def try_read():
+ if not block:
+ if not await conn.can_read(timeout=timeout):
+ return None
+ else:
+ await conn.connect()
+ return await conn.read_response()
+
+ response = await self._execute(conn, try_read)
if conn.health_check_interval and response == self.health_check_response:
# ignore the health check message as user might not expect it