aniztar
aniztar

Reputation: 2913

Deleting a range of entries from a Redis Stream

I want to delete entries of a Redis Stream older than a particular entry ID. But the XDEL command takes each ID explicitly as input. Is there any way to specify a range of IDs which will help when there are large number of entries in the stream? Also trimming a range of entries will also help me recollect unsed memory.

Upvotes: 3

Views: 2106

Answers (1)

sonus21
sonus21

Reputation: 5388

Currently, there's no way.

However, XTRIM is designed to accept different trimming strategies, even if currently only MAXLEN is implemented. Given that this is an explicit command, it is possible that in the future it will allow to specify trimming by time, because the user calling this command in a stand-alone way is supposed to know what she or he is doing.

One useful eviction strategy that XTRIM should have is probably the ability to remove by a range of IDs. This is currently not possible, but will be likely implemented in the future in order to more easily use XRANGE and XTRIM together to move data from Redis to other storage systems if needed.

You can use XTRIM to claim the space, in XTRIM you can give the desired length.

XTRIM mystream MAXLEN ~ 1000

In this 1000 is the size of remaining stream, it could be more or less, it's an approximate number.

Ref: https://redis.io/topics/streams-intro

Upvotes: 1

Related Questions