spring-data-redis
spring-data-redis copied to clipboard
Support for approximate trimming in XAddOptions
XADD
command offers another option called approximateTrimming
along with MAXLEN
About XADD mystream MAXLEN ~ 1000
in this link
However trimming with MAXLEN can be expensive: streams are represented by macro nodes into a radix tree, in order to be very memory efficient. Altering the single macro node, consisting of a few tens of elements, is not optimal. So it's possible to use the command in the following special form:
XADD mystream MAXLEN ~ 1000 * ... entry fields here ...
The ~ argument between the MAXLEN option and the actual count means, I don't really need this to be exactly 1000 items. It can be 1000 or 1010 or 1030, just make sure to save at least 1000 items. With this argument, the trimming is performed only when we can remove a whole node. This makes it much more efficient, and it is usually what you want.
Lettuce driver supports with this issue: #https://github.com/lettuce-io/lettuce-core/issues/846
It would be nice to chain it with maxlen:
RedisStreamCommands.XAddOptions
.maxlen(STREAM_LENGHT)
.approximateTrimming(true)
also for Reactive:
ReactiveStreamCommands.AddStreamRecord
.maxlen(STREAM_LENGTH)
.approximateTrimming(true)
we can check this option in: org.springframework.data.redis.connection.lettuce.LettuceStreamCommands#xAdd
Thanks for your suggestion. Would you be interested in contributing to Spring Data by submitting a pull request?
@mp911de Yes, why not. I'm interested with it but cannot promise to any date yet.
Fixed via #2247