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 with a initialValue that overwrites the existing value at
redisCounter . |
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 with a initialValue that overwrites the existing value. |
Modifier and Type | Method and Description |
---|---|
long |
accumulateAndGet(long updateValue,
LongBinaryOperator accumulatorFunction)
Atomically update the current value using the given
accumulator function . |
long |
addAndGet(long delta)
Atomically add the given value to current value.
|
boolean |
compareAndSet(long expect,
long update)
Atomically set the value to the given updated value if the current value
== the expected value. |
long |
decrementAndGet()
Atomically decrement 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()
Get the current value.
|
long |
getAndAccumulate(long updateValue,
LongBinaryOperator accumulatorFunction)
Atomically update the current value using the given
accumulator function . |
long |
getAndAdd(long delta)
Atomically add the given value to current value.
|
long |
getAndDecrement()
Atomically decrement by one the current value.
|
long |
getAndIncrement()
Atomically increment by one the current value.
|
long |
getAndSet(long newValue)
Set to the given value and return the old value.
|
long |
getAndUpdate(LongUnaryOperator updateFunction)
Atomically update the current value using the given
update function . |
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 increment 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)
Set to the given value.
|
String |
toString() |
long |
updateAndGet(LongUnaryOperator updateFunction)
Atomically update the current value using the given
update function . |
byteValue, shortValue
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
expire, expireAt
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 with a initialValue
that overwrites the existing value at
redisCounter
.redisCounter
- Redis key of this counter.factory
- connection factory.initialValue
- initial value to set.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 with a initialValue
that overwrites the existing value.
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 value.public 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 getAndUpdate(LongUnaryOperator updateFunction)
update function
.updateFunction
- the function which calculates the value to set. Should be a pure function (no side effects),
because it will be applied several times if update attempts fail due to concurrent calls.public long getAndAccumulate(long updateValue, LongBinaryOperator accumulatorFunction)
accumulator function
. The new value
is calculated by applying the accumulator function to the current value and the given updateValue
.updateValue
- the value which will be passed into the accumulator function.accumulatorFunction
- the function which calculates the value to set. Should be a pure function (no side
effects), because it will be applied several times if update attempts fail due to concurrent calls.public long incrementAndGet()
public long decrementAndGet()
public long addAndGet(long delta)
delta
- the value to add.public long updateAndGet(LongUnaryOperator updateFunction)
update function
.updateFunction
- the function which calculates the value to set. Should be a pure function (no side effects),
because it will be applied several times if update attempts fail due to concurrent calls.public long accumulateAndGet(long updateValue, LongBinaryOperator accumulatorFunction)
accumulator function
. The new value
is calculated by applying the accumulator function to the current value and the given updateValue
.updateValue
- the value which will be passed into the accumulator function.accumulatorFunction
- the function which calculates the value to set. Should be a pure function (no side
effects), because it will be applied several times if update attempts fail due to concurrent calls.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–2021 Pivotal Software, Inc.. All rights reserved.