XTRIM

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Trim the stream

Usage: XTRIM key [MAXLEN 10] or MINID ID.

  • MAXLEN: how many entries to keep. 10 keeps 10 entries and deletes the rest.
  • MINID: an ID. Entries with a smaller ID are deleted.
    Added in version 6.2.
  • That number or ID is the threshold.

Example: MAXLEN

Command>XTRIM sensor-1234 MAXLEN 10
Result>(integer) 90
  • If sensor-1234 had 100 entries, this deletes the oldest 90 and keeps the latest 10.

Example: MINID

Command>XTRIM sensor-1234 MINID 1624776143068
Result>(integer) 5
  • Deletes entries whose ID is less than 1624776143068.

Special option ~

~ means about. If sensor-1234 has 1 million entries, deleting 999,990 of them takes time. While that delete runs, XADD and XREAD cannot proceed. Streams that must handle large volume should not stall like that. ~ deletes only as many entries as can be processed quickly.

LIMIT count

This option limits how many entries are deleted.


Syntax

XTRIM key MAXLEN|MINID [=|~] threshold [LIMIT count]

  • Available since version 5.0.0.
  • MINID and LIMIT were added in version 6.2.
  • Time complexity is O(log(N)+M), where N is the number of stream entries and M is the number of entries deleted.
  • Returns the number of deleted IDs.

<< XDELS XTRIM XGROUP >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.