public class RedisAtomicInteger extends Number implements Serializable, BoundKeyOperations<String>
AtomicInteger
,
Serialized FormConstructor and Description |
---|
RedisAtomicInteger(String redisCounter,
RedisConnectionFactory factory)
Constructs a new
RedisAtomicInteger instance. |
RedisAtomicInteger(String redisCounter,
RedisConnectionFactory factory,
int initialValue)
Constructs a new
RedisAtomicInteger instance. |
RedisAtomicInteger(String redisCounter,
RedisOperations<String,Integer> template)
Constructs a new
RedisAtomicInteger instance. |
RedisAtomicInteger(String redisCounter,
RedisOperations<String,Integer> template,
int initialValue)
Constructs a new
RedisAtomicInteger instance. |
Modifier and Type | Method and Description |
---|---|
int |
accumulateAndGet(int updateValue,
IntBinaryOperator accumulatorFunction)
Atomically update the current value using the given
accumulator function . |
int |
addAndGet(int delta)
Atomically add the given value to current value.
|
boolean |
compareAndSet(int expect,
int update)
Atomically set the value to the given updated value if the current value
== the expected value. |
int |
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() |
int |
get()
Get the current value.
|
int |
getAndAccumulate(int updateValue,
IntBinaryOperator accumulatorFunction)
Atomically update the current value using the given
accumulator function . |
int |
getAndAdd(int delta)
Atomically add the given value to current value.
|
int |
getAndDecrement()
Atomically decrement by one the current value.
|
int |
getAndIncrement()
Atomically increment by one the current value.
|
int |
getAndSet(int newValue)
Set to the given value and return the old value.
|
int |
getAndUpdate(IntUnaryOperator 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.
|
int |
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(int newValue)
Set to the given value.
|
String |
toString() |
int |
updateAndGet(IntUnaryOperator updateFunction)
Atomically update the current value using the given
update function . |
byteValue, shortValue
public RedisAtomicInteger(String redisCounter, RedisConnectionFactory factory)
RedisAtomicInteger
instance. Uses the value existing in Redis or 0 if none is found.redisCounter
- Redis key of this counter.factory
- connection factory.public RedisAtomicInteger(String redisCounter, RedisConnectionFactory factory, int initialValue)
RedisAtomicInteger
instance.redisCounter
- Redis key of this counter.factory
- connection factory.initialValue
- initial value to set if the Redis key is absent.public RedisAtomicInteger(String redisCounter, RedisOperations<String,Integer> template)
RedisAtomicInteger
instance. Uses the value existing in Redis or 0 if none is found.redisCounter
- Redis key of this counter.template
- the template.RedisAtomicInteger(String, RedisConnectionFactory, int)
public RedisAtomicInteger(String redisCounter, RedisOperations<String,Integer> template, int initialValue)
RedisAtomicInteger
instance. Note: You need to configure the given template
with
appropriate RedisSerializer
for the key and value. As an alternative one could use the
RedisAtomicInteger(String, RedisConnectionFactory, Integer)
constructor which uses appropriate default
serializers.redisCounter
- Redis key of this counter.template
- the template.initialValue
- initial value to set if the Redis key is absent.public int get()
public void set(int newValue)
newValue
- the new value.public int getAndSet(int newValue)
newValue
- the new value.public boolean compareAndSet(int expect, int update)
==
the expected value.expect
- the expected value.update
- the new value.public int getAndIncrement()
public int getAndDecrement()
public int getAndAdd(int delta)
delta
- the value to add.public int getAndUpdate(IntUnaryOperator 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. Must not be
null.public int getAndAccumulate(int updateValue, IntBinaryOperator 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. Must
not be null.public int incrementAndGet()
public int decrementAndGet()
public int addAndGet(int delta)
delta
- the value to add.public int updateAndGet(IntUnaryOperator 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. Must not be
null.public int accumulateAndGet(int updateValue, IntBinaryOperator 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. Must
not be null.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–2019 Pivotal Software, Inc.. All rights reserved.