Redis Commands

Docs  >   Redis Commands   >  X   >   Xtrim

Top

XTRIM trims the stream by evicting older entries (entries with lower IDs) if needed.

Trimming the stream can be done using one of these strategies:

  • MAXLEN: Evicts entries as long as the stream's length exceeds the specified threshold, where threshold is a positive integer.
  • MINID: Evicts entries with IDs lower than threshold, where threshold is a stream ID.

For example, this will trim the stream to exactly the latest 1000 items:

XTRIM mystream MAXLEN 1000

Whereas in this example, all entries that have an ID lower than 649085820-0 will be evicted:

XTRIM mystream MINID 649085820

By default, or when provided with the optional = argument, the command performs exact trimming.

Depending on the strategy, exact trimming means:

  • MAXLEN: the trimmed stream's length will be exactly the minimum between its original length and the specified threshold.
  • MINID: the oldest ID in the stream will be exactly the maximum between its original oldest ID and the specified threshold.

Nearly exact trimming