Skip to content
Advertisement

Redisson RRingBuffer capacity cannot be changed dynamically under the same key

currently I’m working on software where I would like to use Redis to store some data. Specifically, I would like to use the RRingBuffer where I initially set capacity and it can change during the runtime. My idea was that a new RB is created and the data from oldRB is moved to newRB For example, maybe this is wrong:

    // has some data that is created earlier with a capacity of 4
    final RRingBuffer<String> oldRB = cache.get(SOME_KEY);
    
    log.info(oldRB);

    // new ring buffer with  
    final RRingBuffer<String> newRB = redisson.getRingBuffer(A_NEW_RING_BUFFER);
    newRB.trySetCapacity(3);

    add the data from oldRB to newRB...

    cache.put(SOME_KEY, newRB)
    
    log.info(newRB)
    -------------------------------------------
    CONSOLE:
    info: ["one", "two", "three", "four", "five"]
    info: ["three", "four", "five"]

This is initially working but it seems like Redis caches this RB with the initial capacity and cannot change it.

Advertisement

Answer

RRingBuffer.setCapacity() method added in Redisson 3.13.5. So you can change capacity without buffer state copying.

7 People found this is helpful
Advertisement