Skip to content

Commit e01e4dc

Browse files
committed
Allow pubsub.get_message(time=None) to block.
1 parent ee37f2c commit e01e4dc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

redis/asyncio/client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -867,16 +867,16 @@ async def listen(self) -> AsyncIterator:
867867
yield response
868868

869869
async def get_message(
870-
self, ignore_subscribe_messages: bool = False, timeout: float = 0.0
870+
self, ignore_subscribe_messages: bool = False, timeout: Optional[float] = 0.0
871871
):
872872
"""
873873
Get the next message if one is available, otherwise None.
874874
875875
If timeout is specified, the system will wait for `timeout` seconds
876876
before returning. Timeout should be specified as a floating point
877-
number.
877+
number or None to wait indefinitely.
878878
"""
879-
response = await self.parse_response(block=False, timeout=timeout)
879+
response = await self.parse_response(block=(timeout is None), timeout=timeout)
880880
if response:
881881
return await self.handle_message(response, ignore_subscribe_messages)
882882
return None

redis/client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1623,13 +1623,13 @@ def listen(self):
16231623
if response is not None:
16241624
yield response
16251625

1626-
def get_message(self, ignore_subscribe_messages=False, timeout=0):
1626+
def get_message(self, ignore_subscribe_messages=False, timeout=0.0):
16271627
"""
16281628
Get the next message if one is available, otherwise None.
16291629
16301630
If timeout is specified, the system will wait for `timeout` seconds
16311631
before returning. Timeout should be specified as a floating point
1632-
number.
1632+
number, or None, to wait indefinitely.
16331633
"""
16341634
if not self.subscribed:
16351635
# Wait for subscription
@@ -1645,7 +1645,7 @@ def get_message(self, ignore_subscribe_messages=False, timeout=0):
16451645
# so no messages are available
16461646
return None
16471647

1648-
response = self.parse_response(block=False, timeout=timeout)
1648+
response = self.parse_response(block=(timeout is None), timeout=timeout)
16491649
if response:
16501650
return self.handle_message(response, ignore_subscribe_messages)
16511651
return None

0 commit comments

Comments
 (0)