XTRIM

Since 1.1.0Streams

Syntax

XTRIM key MAXLEN|MINID [=|~] threshold [LIMIT count] [KEEPREF | DELREF | ACKED]
  • Flags: write
  • ACL categories: @slow, @stream, @write
  • Arity: -4

Removes the oldest entries of the stream at key.

Options

OptionEffect
MAXLEN nKeep the newest n entries.
MINID idRemove the entries with IDs below id.
~Trim approximately: whole nodes of stream-node-max-entries entries at a time, which is cheaper. = is exact (the default).
LIMIT countWith ~, remove at most count entries. Without ~ it is an error, as in Redis.
KEEPREFLeave consumer groups' pending references to removed entries (the default).
DELREFRemove those references too.
ACKEDStop at the first entry that some group has not acknowledged.

Reply

  • The number of entries removed.

Examples

> XADD u 1-0 a 1
"1-0"
> XADD u 2-0 a 2
"2-0"
> XADD u 3-0 a 3
"3-0"
> XTRIM u MAXLEN 1
(integer) 2
> XTRIM u MAXLEN 1 LIMIT 10
(error) ERR syntax error, LIMIT cannot be used without the special ~ option