Redis › Streams
How do you limit the size of a Redis Stream to prevent it from growing indefinitely and consuming unlimited memory?
IntermediateAnswer
You use the MAXLEN option when adding entries with XADD, either specifying an exact maximum length or using the approximate trimming option for better performance, which automatically removes the oldest entries once the stream exceeds the specified length, keeping its memory usage bounded over time.
XADD mystream MAXLEN '~' 10000 '*' field 'value'Real-world example A high volume logging system caps its stream at approximately ten thousand entries, automatically discarding the oldest log entries as new ones arrive, preventing the stream from consuming unbounded memory over time.