Skip to content

Commit 9a97fe3

Browse files
committed
Allow pubsub.get_message(time=None) to block.
1 parent 0da78c8 commit 9a97fe3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

redis/asyncio/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,16 +872,16 @@ async def listen(self) -> AsyncIterator:
872872
yield response
873873

874874
async def get_message(
875-
self, ignore_subscribe_messages: bool = False, timeout: float = 0.0
875+
self, ignore_subscribe_messages: bool = False, timeout: Optional[float] = 0.0
876876
):
877877
"""
878878
Get the next message if one is available, otherwise None.
879879
880880
If timeout is specified, the system will wait for `timeout` seconds
881881
before returning. Timeout should be specified as a floating point
882-
number.
882+
number or None to wait indefinitely.
883883
"""
884-
response = await self.parse_response(block=False, timeout=timeout)
884+
response = await self.parse_response(block=(timeout is None), timeout=timeout)
885885
if response:
886886
return await self.handle_message(response, ignore_subscribe_messages)
887887
return None

redis/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,13 +1637,13 @@ def listen(self):
16371637
if response is not None:
16381638
yield response
16391639

1640-
def get_message(self, ignore_subscribe_messages=False, timeout=0):
1640+
def get_message(self, ignore_subscribe_messages=False, timeout=0.0):
16411641
"""
16421642
Get the next message if one is available, otherwise None.
16431643
16441644
If timeout is specified, the system will wait for `timeout` seconds
16451645
before returning. Timeout should be specified as a floating point
1646-
number.
1646+
number, or None, to wait indefinitely.
16471647
"""
16481648
if not self.subscribed:
16491649
# Wait for subscription
@@ -1659,7 +1659,7 @@ def get_message(self, ignore_subscribe_messages=False, timeout=0):
16591659
# so no messages are available
16601660
return None
16611661

1662-
response = self.parse_response(block=False, timeout=timeout)
1662+
response = self.parse_response(block=(timeout is None), timeout=timeout)
16631663
if response:
16641664
return self.handle_message(response, ignore_subscribe_messages)
16651665
return None

0 commit comments

Comments
 (0)