+ atomic counters support reading values from the backing store (rather then always use 0)

This commit is contained in:
Costin Leau
2010-12-15 12:14:15 +02:00
parent b4f5f884e5
commit 0f91ced5a0
2 changed files with 22 additions and 4 deletions

View File

@@ -36,13 +36,22 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
private RedisOperations<String, Integer> generalOps;
/**
* Constructs a new <code>RedisAtomicInteger</code> instance with an initial value of zero.
* Constructs a new <code>RedisAtomicInteger</code> instance. Uses as initial value
* the data from the backing store (sets the counter to 0 if no value is found).
*
* Use {@link #RedisAtomicInteger(String, RedisOperations, int)} to set the counter to a certain value
* as an alternative constructor or {@link #set(int)}.
*
* @param redisCounter
* @param operations
*/
public RedisAtomicInteger(String redisCounter, RedisOperations<String, Integer> operations) {
this(redisCounter, operations, 0);
this.key = redisCounter;
this.operations = operations.getValueOps();
this.generalOps = operations;
if (this.operations.get(redisCounter) == null) {
set(0);
}
}
/**

View File

@@ -36,13 +36,22 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
private RedisOperations<String, Long> generalOps;
/**
* Constructs a new <code>RedisAtomicLong</code> instance with an initial value of zero.
* Constructs a new <code>RedisAtomicLong</code> instance. Uses as initial value
* the data from the backing store (sets the counter to 0 if no value is found).
*
* Use {@link #RedisAtomicLong(String, RedisOperations, int)} to set the counter to a certain value
* as an alternative constructor or {@link #set(int)}.
*
* @param redisCounter
* @param operations
*/
public RedisAtomicLong(String redisCounter, RedisOperations<String, Long> operations) {
this(redisCounter, operations, 0);
this.key = redisCounter;
this.operations = operations.getValueOps();
this.generalOps = operations;
if (this.operations.get(redisCounter) == null) {
set(0);
}
}
/**