Redisson RRingBuffer的容量不能在相同的键下动态更改。

huangapple go评论78阅读模式
英文:

Redisson RRingBuffer capacity cannot be changed dynamically under the same key

问题

目前我正在开发的软件中,我希望使用Redis来存储一些数据。具体而言,我想使用RRingBuffer,我最初设置了容量,但它可以在运行时更改。我的想法是创建一个新的RB,并将旧RB中的数据移动到新RB中。例如,也许这是错误的:

// 之前以容量4创建的一些数据
final RRingBuffer<String> oldRB = cache.get(SOME_KEY);

log.info(oldRB);

// 新的环形缓冲区
final RRingBuffer<String> newRB = redisson.getRingBuffer(A_NEW_RING_BUFFER);
newRB.trySetCapacity(3);

将旧RB中的数据添加到新RB中...

cache.put(SOME_KEY, newRB)

log.info(newRB)

初始情况下,这似乎是有效的,但似乎Redis会将这个带有初始容量的RB缓存起来,而且无法更改它。

英文:

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&lt;String&gt; oldRB = cache.get(SOME_KEY);
    
    log.info(oldRB);

    // new ring buffer with  
    final RRingBuffer&lt;String&gt; 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: [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;, &quot;four&quot;, &quot;five&quot;]
    info: [&quot;three&quot;, &quot;four&quot;, &quot;five&quot;]

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

答案1

得分: 1

RRingBuffer.setCapacity()方法在Redisson 3.13.5中添加。因此,您可以在不复制缓冲区状态的情况下更改容量。

英文:

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

huangapple
  • 本文由 发表于 2020年8月14日 22:45:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/63415008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定