I am trying out spring data redis using reactive Redis template. However, i had no success so far in finding the Xargs
for limiting the size of the stream.
Base lettuce implementation has that option in native implementation:
commands
.xadd(streamKey, XAddArgs.Builder.maxlen(200L), eventKey,
record);
However, this option is unavailable in RedisTemplate
AFAIK. The maxlen
option is inevitable as the stream might grow exponentially.
If someone has encountered it, can you point me to the right place?
Thanks all.
2
Answers
There is no support for
XADD
withMAXLEN
in the[StreamOperations][1]
interface of RedisTemplate.You can pipeline the
add(...)
withtrim(K key, long count)
(XTRIM
) to get a similar effect. The two commands would be sent simultaneously, so you only have one Round Trip Time.XTRIM
is an expensive operation compared toXADD
. Consider trimming every now and then on a separate logic instead of with everyXADD
.Sadly, the
MAXLEN ~
doesn’t seem to be supported either, so we are left with exact count trimming only on RedisTemplate.Not sure this is a good option, for me I use this way to limit the size of stream instead of using xadd cause redisTemplate doesn’t support xadd
First, I trim the stream to remove and limit my size. At below, i use 1000 entries
Then, I add the next data like normal
So my data in the stream is always around 1000 entries