Skip to content

Commit

Permalink
fix:xread blocking without count
Browse files Browse the repository at this point in the history
fix #308
  • Loading branch information
cunla committed May 10, 2024
1 parent 51a0c10 commit 3fee210
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions fakeredis/commands_mixins/streams_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion test/test_mixins/test_streams_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down Expand Up @@ -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"})
Expand Down

0 comments on commit 3fee210

Please sign in to comment.