Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/t_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,15 @@ int64_t streamTrim(stream *s, streamAddTrimArgs *args) {

if (trim_strategy == TRIM_STRATEGY_NONE) return 0;
if (trim_strategy == TRIM_STRATEGY_MAXLEN && s->length <= maxlen) return 0;
if (trim_strategy == TRIM_STRATEGY_MAXLEN && maxlen == 0 && !approx && limit == 0) {
int64_t deleted = s->length;
raxFreeWithCallback(s->rax, lpFreeVoid);
s->rax = raxNew();
s->length = 0;
s->first_id.ms = 0;
s->first_id.seq = 0;
return deleted;
}

raxIterator ri;
raxStart(&ri, s->rax);
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/type/stream.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,18 @@ start_server {
assert {[r XLEN mystream] == 400}
}

test {XTRIM with MAXLEN 0 keeps an empty stream key} {
r DEL mystream
r XADD mystream 1-0 f v
r XADD mystream 2-0 f v
assert_equal 2 [r XTRIM mystream MAXLEN = 0]
assert_equal 1 [r EXISTS mystream]
set reply [r XINFO STREAM mystream]
assert_equal 0 [dict get $reply length]
assert_equal "2-0" [dict get $reply last-generated-id]
assert_equal "0-0" [dict get $reply recorded-first-entry-id]
}

test {XADD with LIMIT consecutive calls} {
r del mystream
r config set stream-node-max-entries 10
Expand Down
Loading