public class RedisAtomicLong extends Number implements Serializable, BoundKeyOperations<String>
AtomicLong
,
Serialized FormConstructor 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() |
byteValue, shortValue
public RedisAtomicLong(String redisCounter, RedisConnectionFactory factory)
RedisAtomicLong
instance. Uses the value existing in Redis or 0 if none is found.redisCounter
- Redis key of this counter.factory
- connection factory.public RedisAtomicLong(String redisCounter, RedisConnectionFactory factory, long initialValue)
RedisAtomicLong
instance.redisCounter
- Redis key of this counter.factory
- connection factory.initialValue
- initial value to set if the Redis key is absent.public RedisAtomicLong(String redisCounter, RedisOperations<String,Long> template)
RedisAtomicLong
instance. Uses the value existing in Redis or 0 if none is found.redisCounter
- Redis key of this counter.template
- the template.RedisAtomicLong(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
- Redis key of this counter.template
- the templateinitialValue
- initial value to set if the Redis key is absent.public long get()
public void set(long newValue)
newValue
- the new valuepublic long getAndSet(long newValue)
newValue
- the new value.public boolean compareAndSet(long expect, long update)
==
the expected value.expect
- the expected value.update
- the new value.public long getAndIncrement()
public long getAndDecrement()
public long getAndAdd(long delta)
delta
- the value to add.public long incrementAndGet()
public long decrementAndGet()
public long addAndGet(long delta)
delta
- the value to add.public String toString()
public String getKey()
BoundKeyOperations
getKey
in interface BoundKeyOperations<String>
public DataType getType()
BoundKeyOperations
getType
in interface BoundKeyOperations<String>
public Long getExpire()
BoundKeyOperations
getExpire
in interface BoundKeyOperations<String>
public Boolean expire(long timeout, TimeUnit unit)
BoundKeyOperations
expire
in interface BoundKeyOperations<String>
timeout
- expiration valueunit
- expiration unitpublic Boolean expireAt(Date date)
BoundKeyOperations
expireAt
in interface BoundKeyOperations<String>
date
- expiration datepublic Boolean persist()
BoundKeyOperations
persist
in interface BoundKeyOperations<String>
public void rename(String newKey)
BoundKeyOperations
rename
in interface BoundKeyOperations<String>
newKey
- new key. Must not be null.public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
Copyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.