diff --git a/fakeredis/commands_mixins/streams_mixin.py b/fakeredis/commands_mixins/streams_mixin.py index e659c85a..f7f0e1c9 100644 --- a/fakeredis/commands_mixins/streams_mixin.py +++ b/fakeredis/commands_mixins/streams_mixin.py @@ -368,10 +368,10 @@ def _xread(self, stream_start_id_list: List[Tuple[bytes, StreamRangeTest]], coun for stream_name, start_id in stream_start_id_list: item = CommandItem(stream_name, self._db, item=self._db.get(stream_name), default=None) stream_results = self._xrange(item.value, start_id, max_inf, False, count) - if first_pass and (count is None): - return None if len(stream_results) > 0: res.append([item.key, stream_results]) + if first_pass and (count is None): + return res if blocking and count and len(res) == 0: return None return res diff --git a/test/test_mixins/test_streams_commands.py b/test/test_mixins/test_streams_commands.py index be5ed0a2..8bf58052 100644 --- a/test/test_mixins/test_streams_commands.py +++ b/test/test_mixins/test_streams_commands.py @@ -61,8 +61,8 @@ def test_xadd_redis__green(r: redis.Redis): stream = "stream" before = int(1000 * time.time()) m1 = r.xadd(stream, {"some": "other"}) - after = int(1000 * time.time()) + 1 ts1, seq1 = m1.decode().split('-') + after = int(1000 * time.time()) + 1 assert before <= int(ts1) <= after seq1 = int(seq1) m2 = r.xadd(stream, {'add': 'more'}, id=f'{ts1}-{seq1 + 1}') @@ -233,6 +233,14 @@ def get_stream_message(client, stream, message_id): return response[0] +def test_xread_blocking_no_count(r: redis.Redis): + k = "key" + r.xadd(k, {"value": 1234}) + streams = {k: "0"} + m1 = r.xread(streams=streams, block=10) + assert m1[0][1][0][1] == {b'value': b'1234'} + + def test_xread(r: redis.Redis): stream = "stream" m1 = r.xadd(stream, {"foo": "bar"})