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, 5 insertions, 17 deletions
diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py
index c13054b..0e40ed7 100644
--- a/redis/asyncio/client.py
+++ b/redis/asyncio/client.py
@@ -24,8 +24,6 @@ from typing import (
cast,
)
-import async_timeout
-
from redis.asyncio.connection import (
Connection,
ConnectionPool,
@@ -759,18 +757,8 @@ class PubSub:
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
-
- response = await self._execute(conn, read_with_timeout)
- else:
- response = await self._execute(conn, conn.read_response)
+ read_timeout = None if block else timeout
+ response = await self._execute(conn, conn.read_response, timeout=read_timeout)
if conn.health_check_interval and response == self.health_check_response:
# ignore the health check message as user might not expect it
@@ -882,16 +870,16 @@ class PubSub:
yield response
async def get_message(
- self, ignore_subscribe_messages: bool = False, timeout: float = 0.0
+ self, ignore_subscribe_messages: bool = False, timeout: Optional[float] = 0.0
):
"""
Get the next message if one is available, otherwise None.
If timeout is specified, the system will wait for `timeout` seconds
before returning. Timeout should be specified as a floating point
- number.
+ number or None to wait indefinitely.
"""
- response = await self.parse_response(block=False, timeout=timeout)
+ response = await self.parse_response(block=(timeout is None), timeout=timeout)
if response:
return await self.handle_message(response, ignore_subscribe_messages)
return None