Hazelcast 缓存中有类似 Compare-And-Set 的东西吗?
Is there something like Compare-And-Set in Hazelcast cache?
我需要在缓存中将一些对象粘合在一起。我从不同的 hazelcast 节点上的队列中接收到这些对象。
示例。
Node 1 receives message "message 1. part 1"
Node 2 receives message "message 1. part 2"
One of the nodes should send to the output full message 1.
@sinedsem,最简单的解决方案如下:
Value oldValue = imap.get(key)
Value newValue = oldValue;
if (newValue == null) newValue = new Value()
//Either set part1 or part 2 depends on the node
newValue.setPart1(part1)
imap.replace(key, oldValue, newValue)
你也可以查看这个例子:http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#optimistic-locking
我需要在缓存中将一些对象粘合在一起。我从不同的 hazelcast 节点上的队列中接收到这些对象。
示例。
Node 1 receives message "message 1. part 1"
Node 2 receives message "message 1. part 2"
One of the nodes should send to the output full message 1.
@sinedsem,最简单的解决方案如下:
Value oldValue = imap.get(key)
Value newValue = oldValue;
if (newValue == null) newValue = new Value()
//Either set part1 or part 2 depends on the node
newValue.setPart1(part1)
imap.replace(key, oldValue, newValue)
你也可以查看这个例子:http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#optimistic-locking