从 Redis 流中删除一系列条目

Deleting a range of entries from a Redis Stream

我想删除早于特定条目 ID 的 Redis 流条目。但是 XDEL 命令明确地将每个 ID 作为输入。当流中有大量条目时,有什么方法可以指定 ID 范围吗?此外,修剪一系列条目也将帮助我回忆起未使用的记忆。

目前没有办法。

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.

您可以使用 XTRIM 声明 space,在 XTRIM 中您可以提供所需的长度。

XTRIM mystream MAXLEN ~ 1000

这里1000是剩余流的大小,可以多也可以少,是个大概数。

参考:https://redis.io/topics/streams-intro