Skip to content

Commit

Permalink
fix:bug showing stream does not exist if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Jun 28, 2024
1 parent 509e895 commit b32ce43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions fakeredis/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ def add(self, fields: Sequence[bytes], entry_key: str = "*") -> Union[None, byte
self._entries_added += 1
return ts_seq.encode()

def __bool__(self):
return True

def __len__(self) -> int:
return len(self._ids)

Expand Down
14 changes: 13 additions & 1 deletion test/test_mixins/test_streams_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,4 +792,16 @@ def thread_func():
t.join()
assert result[0][0] == b"stream"
assert result[0][1][0][1] == {b'x': b'1'}
pass


def test_stream_ttl(r: redis.Redis):
stream = "stream"

m1 = r.xadd(stream, {'foo': 'bar'})
expected = [[
stream.encode(),
[get_stream_message(r, stream, m1)],
]]
assert r.xread(streams={stream: 0}) == expected
assert r.xtrim(stream, 0) == 1
assert r.ttl(stream) == -1

0 comments on commit b32ce43

Please sign in to comment.