CodePark/ questions / Pub/Sub & Streams
START PRACTICINGPRACTICE
Backend question · Redis & caching › Pub/Sub & Streams

What does the ~ do in this command?

XADD events MAXLEN ~ 1000 * type click
It trims approximately: at least 1000 entries are kept, possibly a few more, which is much cheaper

~ makes the trim approximate. Redis keeps at least 1000 entries, maybe a few more, and the trim is much cheaper. With ~, Redis trims only when it can remove whole internal nodes of the stream. So it may keep slightly more than 1000 entries, but never fewer. Without ~, or with =, the trim is exact, so "It keeps exactly 1000 entries, trimming one-by-one" describes the exact version, which costs more. Reads never skip entries. Stream entries have no TTLs, so "It sets a TTL of about 1000 seconds on new entries" is wrong too.