+ atomic counters support reading values from the backing store (rather then always use 0)
This commit is contained in:
@@ -36,13 +36,22 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
|
|||||||
private RedisOperations<String, Integer> generalOps;
|
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 redisCounter
|
||||||
* @param operations
|
* @param operations
|
||||||
*/
|
*/
|
||||||
public RedisAtomicInteger(String redisCounter, RedisOperations<String, Integer> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,13 +36,22 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
|
|||||||
private RedisOperations<String, Long> generalOps;
|
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 redisCounter
|
||||||
* @param operations
|
* @param operations
|
||||||
*/
|
*/
|
||||||
public RedisAtomicLong(String redisCounter, RedisOperations<String, Long> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user