+ fix problem causing atomic counters to reinitialize Redis values (even if no value was given)
This commit is contained in:
@@ -77,8 +77,10 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey
|
||||
this.generalOps = redisTemplate;
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null || this.operations.get(redisCounter) == null) {
|
||||
set(0);
|
||||
if (initialValue == null) {
|
||||
if (this.operations.get(redisCounter) == null) {
|
||||
set(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
set(initialValue);
|
||||
|
||||
@@ -77,8 +77,10 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe
|
||||
this.generalOps = redisTemplate;
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null || this.operations.get(redisCounter) == null) {
|
||||
set(0);
|
||||
if (initialValue == null) {
|
||||
if (this.operations.get(redisCounter) == null) {
|
||||
set(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
set(initialValue);
|
||||
|
||||
@@ -105,4 +105,11 @@ public class RedisAtomicTests {
|
||||
int delta = 5;
|
||||
assertEquals(delta, intCounter.addAndGet(delta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadExistingValue() throws Exception {
|
||||
longCounter.set(5);
|
||||
RedisAtomicLong keyCopy = new RedisAtomicLong(longCounter.getKey(), factory);
|
||||
assertEquals(longCounter.get(), keyCopy.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user