skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    redisTemplate.opsForStream().trim("Stream Key",1000);
    

    Then, I add the next data like normal

    redisTemplate.opsForStream().add(...)
    

    So my data in the stream is always around 1000 entries

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search