Stream

XTRIM

Trims the stream by removing entries to keep it at a reasonable size.

Arguments

keybodystrrequired

The key of the stream.

maxlenbodyint

The maximum number of entries to keep in the stream. Mutually exclusive with minid.

approximatebodybooldefault: True

Use approximate trimming (more efficient). When True, Redis may keep slightly more entries than specified. Defaults to True.

minidbodystr

The minimum ID to keep. Entries with IDs lower than this will be removed. Mutually exclusive with maxlen.

limitbodyint

Limit how many entries will be trimmed at most.

Response

int

The number of entries removed from the stream.

Approximate trim (default)
result = redis.xtrim("mystream", maxlen=50)
Approximate trim (explicit)
result = redis.xtrim("mystream", maxlen=50, approximate=True)
Exact trim
result = redis.xtrim("mystream", maxlen=20, approximate=False)
Trim by minimum ID
result = redis.xtrim("mystream", minid="1638360173533-0")
Approximate trim with limit
result = redis.xtrim("mystream", maxlen=1000, approximate=True, limit=100)
Loading search…