Search code examples
springredisspring-webfluxspring-data-redis

No maxlen option to limit stream size in spring data reactive Redis Template


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.


Solution

  • There is no support for XADD with MAXLEN in the [StreamOperations][1] interface of RedisTemplate.

    You can pipeline the add(...) with trim(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 to XADD. Consider trimming every now and then on a separate logic instead of with every XADD.

    Sadly, the MAXLEN ~ doesn't seem to be supported either, so we are left with exact count trimming only on RedisTemplate.