Hi Assen,
Every key-value operation is atomic. The record, relating to the key, is locked at the start of the operation and unlocked at the end of the operation. This means that the add()
operation is atomic.
I suspect that you want to increment the counter and get the new value. If so, this can be done in a single operation atomically by using operate()
. Here is an example that increments a counter and gets the new value, similar to INCR
in Redis:
String binName = "my_counter";
Key key = new Key("test", "demo", "my-record-that-has-a-counter");
Record record = aerospikeClient.operate(null, key, Operation.add(new Bin(binName, 1)), Operation.get(binName));
long counterValue = record.getLong(binName);
I hope this helps
Peter