Introduction
XTRIM helps keep a Redis stream from growing too big by removing old entries. This saves space and keeps your data fresh.
XTRIM key MAXLEN [~] count
XTRIM mystream MAXLEN 100XTRIM mystream MAXLEN ~ 1000XADD mystream * sensor-id 1 temperature 22.5 XADD mystream * sensor-id 2 temperature 23.0 XADD mystream * sensor-id 3 temperature 21.8 XTRIM mystream MAXLEN 2 XRANGE mystream - +
XTRIM command do when used with the MAXLEN option?XTRIM command with MAXLEN is used to keep the stream size limited by removing old entries.mystream to keep at most 1000 entries approximately?XTRIM command.XTRIM mystream MAXLEN ~1000 with spaces separating arguments.XADD mystream * field1 value1 XADD mystream * field2 value2 XADD mystream * field3 value3 XTRIM mystream MAXLEN 2
mystream contain after these commands?mystream using XADD.XTRIM command trims the stream to keep only the latest 2 entries, removing the oldest one.XTRIM mystream MAXLEN ~1000 but notice the stream still has over 2000 entries. What is the most likely reason?events capped at 500 entries but want to improve trimming speed by allowing approximate trimming. Which command should you use?MAXLEN.XTRIM events MAXLEN ~500 caps the stream at about 500 entries with faster trimming.Pass the test and this pattern moves unknown