public class RedisAtomicLong extends Number implements Serializable, BoundKeyOperations<String>
AtomicLong,
Serialized Form| Constructor and Description |
|---|
RedisAtomicLong(String redisCounter,
RedisConnectionFactory factory)
Constructs a new
RedisAtomicLong instance. |
RedisAtomicLong(String redisCounter,
RedisConnectionFactory factory,
long initialValue)
Constructs a new
RedisAtomicLong instance. |
RedisAtomicLong(String redisCounter,
RedisOperations<String,Long> template)
Constructs a new
RedisAtomicLong instance. |
RedisAtomicLong(String redisCounter,
RedisOperations<String,Long> template,
long initialValue)
Constructs a new
RedisAtomicLong instance. |
| Modifier and Type | Method and Description |
|---|---|
long |
addAndGet(long delta)
Atomically adds the given value to the current value.
|
boolean |
compareAndSet(long expect,
long update)
Atomically sets the value to the given updated value if the current value
== the expected value. |
long |
decrementAndGet()
Atomically decrements by one the current value.
|
double |
doubleValue() |
Boolean |
expire(long timeout,
TimeUnit unit)
Sets the key time-to-live/expiration.
|
Boolean |
expireAt(Date date)
Sets the key time-to-live/expiration.
|
float |
floatValue() |
long |
get()
Gets the current value.
|
long |
getAndAdd(long delta)
Atomically adds the given value to the current value.
|
long |
getAndDecrement()
Atomically decrements by one the current value.
|
long |
getAndIncrement()
Atomically increments by one the current value.
|
long |
getAndSet(long newValue)
Atomically sets to the given value and returns the old value.
|
Long |
getExpire()
Returns the expiration of this key.
|
String |
getKey()
Returns the key associated with this entity.
|
DataType |
getType()
Returns the associated Redis type.
|
long |
incrementAndGet()
Atomically increments by one the current value.
|
int |
intValue() |
long |
longValue() |
Boolean |
persist()
Removes the expiration (if any) of the key.
|
void |
rename(String newKey)
Renames the key.
|
void |
set(long newValue)
Sets to the given value.
|
String |
toString()
Returns the String representation of the current value.
|
byteValue, shortValuepublic RedisAtomicLong(String redisCounter, RedisConnectionFactory factory)
RedisAtomicLong instance. Uses the value existing in Redis or 0 if none is found.redisCounter - redis counterfactory - connection factorypublic RedisAtomicLong(String redisCounter, RedisConnectionFactory factory, long initialValue)
RedisAtomicLong instance.redisCounter - factory - initialValue - public RedisAtomicLong(String redisCounter, RedisOperations<String,Long> template)
RedisAtomicLong instance. Uses the value existing in Redis or 0 if none is found.redisCounter - the redis countertemplate - the templateRedisAtomicLong(String, RedisConnectionFactory, long)public RedisAtomicLong(String redisCounter, RedisOperations<String,Long> template, long initialValue)
RedisAtomicLong instance.
Note: You need to configure the given template with appropriate RedisSerializer for the key and
value. The key serializer must be able to deserialize to a String and the value serializer must be able to
deserialize to a Long.
As an alternative one could use the RedisAtomicLong(String, RedisConnectionFactory, Long) constructor
which uses appropriate default serializers, in this case StringRedisSerializer for the key and
GenericToStringSerializer for the value.
redisCounter - the redis countertemplate - the templateinitialValue - the initial valuepublic long get()
public void set(long newValue)
newValue - the new valuepublic long getAndSet(long newValue)
newValue - the new valuepublic boolean compareAndSet(long expect,
long update)
== the expected value.expect - the expected valueupdate - the new valuepublic long getAndIncrement()
public long getAndDecrement()
public long getAndAdd(long delta)
delta - the value to addpublic long incrementAndGet()
public long decrementAndGet()
public long addAndGet(long delta)
delta - the value to addpublic String toString()
public float floatValue()
floatValue in class Numberpublic double doubleValue()
doubleValue in class Numberpublic String getKey()
BoundKeyOperationsgetKey in interface BoundKeyOperations<String>public Boolean expire(long timeout, TimeUnit unit)
BoundKeyOperationsexpire in interface BoundKeyOperations<String>timeout - expiration valueunit - expiration unitpublic Boolean expireAt(Date date)
BoundKeyOperationsexpireAt in interface BoundKeyOperations<String>date - expiration datepublic Long getExpire()
BoundKeyOperationsgetExpire in interface BoundKeyOperations<String>public Boolean persist()
BoundKeyOperationspersist in interface BoundKeyOperations<String>public void rename(String newKey)
BoundKeyOperationsrename in interface BoundKeyOperations<String>newKey - new keypublic DataType getType()
BoundKeyOperationsgetType in interface BoundKeyOperations<String>