XTRIM to cap the size of a stream by removing old entries.
MAXLEN keeps at most the given number of entries, dropping the oldest ones, while MINID drops every entry with an ID below a threshold, which is how you trim by age since IDs begin with a millisecond timestamp. The reply is the number of entries removed.
~ makes the trim approximate: the server stops at a convenient boundary and may leave a few extra entries, which is much cheaper on large streams and is the right default for background maintenance. = trims exactly, and LIMIT caps how many entries a single call may evict, which keeps one call from blocking for a long time.
KEEPREF, DELREF, and ACKED decide what happens to consumer group references of the removed entries: KEEPREF, the default, leaves them in place, DELREF removes them from every group’s pending list, and ACKED only removes entries that all groups have read and acknowledged. XADD accepts the same options so a stream can be trimmed as it is written to.
Syntax
Arguments
Response
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples
TCP examples use the TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
upstash_redis
upstash_redis
ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs