Package org.redisson
Class RedissonAtomicLong
- java.lang.Object
-
- org.redisson.RedissonObject
-
- org.redisson.RedissonAtomicLong
-
- All Implemented Interfaces:
RAtomicLong
,RAtomicLongAsync
,RExpirable
,RExpirableAsync
,RObject
,RObjectAsync
public class RedissonAtomicLong extends RedissonObject implements RAtomicLong
Distributed alternative to theAtomicLong
- Author:
- Nikita Koksharov
-
-
Field Summary
-
Fields inherited from class org.redisson.RedissonObject
codec, commandExecutor, name
-
-
Constructor Summary
Constructors Constructor Description RedissonAtomicLong(CommandAsyncExecutor commandExecutor, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
addAndGet(long delta)
Atomically adds the given value to the current value.RFuture<Long>
addAndGetAsync(long delta)
Atomically adds the given value to the current value.boolean
clearExpire()
Clear an expire timeout or expire date for object.RFuture<Boolean>
clearExpireAsync()
Clear an expire timeout or expire date for object in async mode.protected RFuture<Boolean>
clearExpireAsync(String... keys)
boolean
compareAndSet(long expect, long update)
Atomically sets the value to the given updated value only if the current value==
the expected value.RFuture<Boolean>
compareAndSetAsync(long expect, long update)
Atomically sets the value to the given updated value only if the current value==
the expected value.long
decrementAndGet()
Atomically decrements the current value by one.RFuture<Long>
decrementAndGetAsync()
Atomically decrements the current value by one.boolean
expire(long timeToLive, TimeUnit timeUnit)
UseRExpirable.expire(Duration)
insteadboolean
expire(Duration duration)
Sets a timeout for this object.boolean
expire(Instant instant)
Sets an expiration date for this object.RFuture<Boolean>
expireAsync(long timeToLive, TimeUnit timeUnit)
UseRExpirableAsync.expireAsync(Duration)
insteadprotected RFuture<Boolean>
expireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys)
RFuture<Boolean>
expireAsync(Duration duration)
Set a timeout for object.RFuture<Boolean>
expireAsync(Instant instant)
Set an expire date for object.boolean
expireAt(long timestamp)
UseRExpirable.expire(Instant)
insteadboolean
expireAt(Date timestamp)
UseRExpirable.expire(Instant)
insteadRFuture<Boolean>
expireAtAsync(long timestamp)
UseRExpirableAsync.expireAsync(Instant)
insteadprotected RFuture<Boolean>
expireAtAsync(long timestamp, String param, String... keys)
RFuture<Boolean>
expireAtAsync(Date timestamp)
UseRExpirableAsync.expireAsync(Instant)
insteadboolean
expireIfGreater(Duration duration)
Sets a timeout for this object only if it's greater than timeout set before.boolean
expireIfGreater(Instant time)
Sets an expiration date for this object only if it's greater than expiration date set before.RFuture<Boolean>
expireIfGreaterAsync(Duration duration)
RFuture<Boolean>
expireIfGreaterAsync(Instant time)
boolean
expireIfLess(Duration duration)
Sets a timeout for this object only if it's less than timeout set before.boolean
expireIfLess(Instant time)
Sets an expiration date for this object only if it's less than expiration date set before.RFuture<Boolean>
expireIfLessAsync(Duration duration)
RFuture<Boolean>
expireIfLessAsync(Instant time)
boolean
expireIfNotSet(Duration duration)
Sets a timeout for this object only if it hasn't been set before.boolean
expireIfNotSet(Instant time)
Sets an expiration date for this object only if it hasn't been set before.RFuture<Boolean>
expireIfNotSetAsync(Duration duration)
RFuture<Boolean>
expireIfNotSetAsync(Instant time)
boolean
expireIfSet(Duration duration)
Sets a timeout for this object only if it has been already set.boolean
expireIfSet(Instant time)
Sets an expiration date for this object only if it has been already set.RFuture<Boolean>
expireIfSetAsync(Duration duration)
RFuture<Boolean>
expireIfSetAsync(Instant time)
long
get()
Returns current value.long
getAndAdd(long delta)
Atomically adds the given value to the current value.RFuture<Long>
getAndAddAsync(long delta)
Atomically adds the given value to the current value.long
getAndDecrement()
Atomically decrements by one the current value.RFuture<Long>
getAndDecrementAsync()
Atomically decrements by one the current value.long
getAndDelete()
Gets and deletes objectRFuture<Long>
getAndDeleteAsync()
Returns and deletes objectlong
getAndIncrement()
Atomically increments the current value by one.RFuture<Long>
getAndIncrementAsync()
Atomically increments the current value by one.long
getAndSet(long newValue)
Atomically sets the given value and returns the old value.RFuture<Long>
getAndSetAsync(long newValue)
Atomically sets the given value and returns the old value.RFuture<Long>
getAsync()
Returns current value.long
getExpireTime()
Expiration time of Redisson object that has a timeoutRFuture<Long>
getExpireTimeAsync()
Expiration time of Redisson object that has a timeoutlong
incrementAndGet()
Atomically increments the current value by one.RFuture<Long>
incrementAndGetAsync()
Atomically increments the current value by one.long
remainTimeToLive()
Remaining time to live of Redisson object that has a timeoutRFuture<Long>
remainTimeToLiveAsync()
Remaining time to live of Redisson object that has a timeoutvoid
set(long newValue)
Atomically sets the given value.RFuture<Void>
setAsync(long newValue)
Atomically sets the given value.String
toString()
-
Methods inherited from class org.redisson.RedissonObject
addListener, addListener, addListenerAsync, addListenerAsync, copy, copyAsync, delete, deleteAsync, deleteAsync, dump, dumpAsync, encode, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getIdleTime, getIdleTimeAsync, getLockByMapKey, getLockByValue, getName, getRawName, getRawName, isExists, isExistsAsync, migrate, migrateAsync, move, moveAsync, prefixName, removeListener, removeListenerAsync, rename, renameAsync, renamenx, renamenxAsync, restore, restore, restoreAndReplace, restoreAndReplace, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, setName, sizeInMemory, sizeInMemoryAsync, sizeInMemoryAsync, sizeInMemoryAsync, suffixName, toSeconds, toStream, touch, touchAsync, unlink, unlinkAsync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, expireIfGreaterAsync, expireIfGreaterAsync, expireIfLessAsync, expireIfLessAsync, expireIfNotSetAsync, expireIfNotSetAsync, expireIfSetAsync, expireIfSetAsync, getExpireTimeAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RObject
addListener, copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
addListenerAsync, copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
-
-
-
Constructor Detail
-
RedissonAtomicLong
public RedissonAtomicLong(CommandAsyncExecutor commandExecutor, String name)
-
-
Method Detail
-
addAndGet
public long addAndGet(long delta)
Description copied from interface:RAtomicLong
Atomically adds the given value to the current value.- Specified by:
addAndGet
in interfaceRAtomicLong
- Parameters:
delta
- the value to add- Returns:
- the updated value
-
addAndGetAsync
public RFuture<Long> addAndGetAsync(long delta)
Description copied from interface:RAtomicLongAsync
Atomically adds the given value to the current value.- Specified by:
addAndGetAsync
in interfaceRAtomicLongAsync
- Parameters:
delta
- the value to add- Returns:
- the updated value
-
compareAndSet
public boolean compareAndSet(long expect, long update)
Description copied from interface:RAtomicLong
Atomically sets the value to the given updated value only if the current value==
the expected value.- Specified by:
compareAndSet
in interfaceRAtomicLong
- Parameters:
expect
- the expected valueupdate
- the new value- Returns:
- true if successful; or false if the actual value was not equal to the expected value.
-
compareAndSetAsync
public RFuture<Boolean> compareAndSetAsync(long expect, long update)
Description copied from interface:RAtomicLongAsync
Atomically sets the value to the given updated value only if the current value==
the expected value.- Specified by:
compareAndSetAsync
in interfaceRAtomicLongAsync
- Parameters:
expect
- the expected valueupdate
- the new value- Returns:
- true if successful; or false if the actual value was not equal to the expected value.
-
getAndDelete
public long getAndDelete()
Description copied from interface:RAtomicLong
Gets and deletes object- Specified by:
getAndDelete
in interfaceRAtomicLong
- Returns:
- the current value
-
getAndDeleteAsync
public RFuture<Long> getAndDeleteAsync()
Description copied from interface:RAtomicLongAsync
Returns and deletes object- Specified by:
getAndDeleteAsync
in interfaceRAtomicLongAsync
- Returns:
- the current value
-
decrementAndGet
public long decrementAndGet()
Description copied from interface:RAtomicLong
Atomically decrements the current value by one.- Specified by:
decrementAndGet
in interfaceRAtomicLong
- Returns:
- the updated value
-
decrementAndGetAsync
public RFuture<Long> decrementAndGetAsync()
Description copied from interface:RAtomicLongAsync
Atomically decrements the current value by one.- Specified by:
decrementAndGetAsync
in interfaceRAtomicLongAsync
- Returns:
- the updated value
-
get
public long get()
Description copied from interface:RAtomicLong
Returns current value.- Specified by:
get
in interfaceRAtomicLong
- Returns:
- the current value
-
getAsync
public RFuture<Long> getAsync()
Description copied from interface:RAtomicLongAsync
Returns current value.- Specified by:
getAsync
in interfaceRAtomicLongAsync
- Returns:
- the current value
-
getAndAdd
public long getAndAdd(long delta)
Description copied from interface:RAtomicLong
Atomically adds the given value to the current value.- Specified by:
getAndAdd
in interfaceRAtomicLong
- Parameters:
delta
- the value to add- Returns:
- the old value before the add
-
getAndAddAsync
public RFuture<Long> getAndAddAsync(long delta)
Description copied from interface:RAtomicLongAsync
Atomically adds the given value to the current value.- Specified by:
getAndAddAsync
in interfaceRAtomicLongAsync
- Parameters:
delta
- the value to add- Returns:
- the old value before the add
-
getAndSet
public long getAndSet(long newValue)
Description copied from interface:RAtomicLong
Atomically sets the given value and returns the old value.- Specified by:
getAndSet
in interfaceRAtomicLong
- Parameters:
newValue
- the new value- Returns:
- the old value
-
getAndSetAsync
public RFuture<Long> getAndSetAsync(long newValue)
Description copied from interface:RAtomicLongAsync
Atomically sets the given value and returns the old value.- Specified by:
getAndSetAsync
in interfaceRAtomicLongAsync
- Parameters:
newValue
- the new value- Returns:
- the old value
-
incrementAndGet
public long incrementAndGet()
Description copied from interface:RAtomicLong
Atomically increments the current value by one.- Specified by:
incrementAndGet
in interfaceRAtomicLong
- Returns:
- the updated value
-
incrementAndGetAsync
public RFuture<Long> incrementAndGetAsync()
Description copied from interface:RAtomicLongAsync
Atomically increments the current value by one.- Specified by:
incrementAndGetAsync
in interfaceRAtomicLongAsync
- Returns:
- the updated value
-
getAndIncrement
public long getAndIncrement()
Description copied from interface:RAtomicLong
Atomically increments the current value by one.- Specified by:
getAndIncrement
in interfaceRAtomicLong
- Returns:
- the old value
-
getAndIncrementAsync
public RFuture<Long> getAndIncrementAsync()
Description copied from interface:RAtomicLongAsync
Atomically increments the current value by one.- Specified by:
getAndIncrementAsync
in interfaceRAtomicLongAsync
- Returns:
- the old value
-
getAndDecrement
public long getAndDecrement()
Description copied from interface:RAtomicLong
Atomically decrements by one the current value.- Specified by:
getAndDecrement
in interfaceRAtomicLong
- Returns:
- the previous value
-
getAndDecrementAsync
public RFuture<Long> getAndDecrementAsync()
Description copied from interface:RAtomicLongAsync
Atomically decrements by one the current value.- Specified by:
getAndDecrementAsync
in interfaceRAtomicLongAsync
- Returns:
- the previous value
-
set
public void set(long newValue)
Description copied from interface:RAtomicLong
Atomically sets the given value.- Specified by:
set
in interfaceRAtomicLong
- Parameters:
newValue
- the new value
-
setAsync
public RFuture<Void> setAsync(long newValue)
Description copied from interface:RAtomicLongAsync
Atomically sets the given value.- Specified by:
setAsync
in interfaceRAtomicLongAsync
- Parameters:
newValue
- the new value- Returns:
- void
-
expire
public boolean expire(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirable
UseRExpirable.expire(Duration)
instead- Specified by:
expire
in interfaceRExpirable
- Parameters:
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unit- Returns:
true
if the timeout was set andfalse
if not
-
expireAsync
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirableAsync
UseRExpirableAsync.expireAsync(Duration)
instead- Specified by:
expireAsync
in interfaceRExpirableAsync
- Parameters:
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unit- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(long timestamp)
Description copied from interface:RExpirable
UseRExpirable.expire(Instant)
instead- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(long timestamp)
Description copied from interface:RExpirableAsync
UseRExpirableAsync.expireAsync(Instant)
instead- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expire
public boolean expire(Instant instant)
Description copied from interface:RExpirable
Sets an expiration date for this object. When expire date comes the key will automatically be deleted.- Specified by:
expire
in interfaceRExpirable
- Parameters:
instant
- expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireIfSet
public boolean expireIfSet(Instant time)
Description copied from interface:RExpirable
Sets an expiration date for this object only if it has been already set. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfSet
in interfaceRExpirable
- Parameters:
time
- expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireIfSetAsync
public RFuture<Boolean> expireIfSetAsync(Instant time)
- Specified by:
expireIfSetAsync
in interfaceRExpirableAsync
-
expireIfNotSet
public boolean expireIfNotSet(Instant time)
Description copied from interface:RExpirable
Sets an expiration date for this object only if it hasn't been set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfNotSet
in interfaceRExpirable
- Parameters:
time
- expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireIfNotSetAsync
public RFuture<Boolean> expireIfNotSetAsync(Instant time)
- Specified by:
expireIfNotSetAsync
in interfaceRExpirableAsync
-
expireIfGreater
public boolean expireIfGreater(Instant time)
Description copied from interface:RExpirable
Sets an expiration date for this object only if it's greater than expiration date set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfGreater
in interfaceRExpirable
- Parameters:
time
- expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireIfGreaterAsync
public RFuture<Boolean> expireIfGreaterAsync(Instant time)
- Specified by:
expireIfGreaterAsync
in interfaceRExpirableAsync
-
expireIfLess
public boolean expireIfLess(Instant time)
Description copied from interface:RExpirable
Sets an expiration date for this object only if it's less than expiration date set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfLess
in interfaceRExpirable
- Parameters:
time
- expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireIfLessAsync
public RFuture<Boolean> expireIfLessAsync(Instant time)
- Specified by:
expireIfLessAsync
in interfaceRExpirableAsync
-
expireAsync
public RFuture<Boolean> expireAsync(Instant instant)
Description copied from interface:RExpirableAsync
Set an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAsync
in interfaceRExpirableAsync
- Parameters:
instant
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expire
public boolean expire(Duration duration)
Description copied from interface:RExpirable
Sets a timeout for this object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expire
in interfaceRExpirable
- Parameters:
duration
- timeout before object will be deleted- Returns:
true
if the timeout was set andfalse
if not
-
expireAsync
public RFuture<Boolean> expireAsync(Duration duration)
Description copied from interface:RExpirableAsync
Set a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expireAsync
in interfaceRExpirableAsync
- Parameters:
duration
- timeout before object will be deleted- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(Date timestamp)
Description copied from interface:RExpirable
UseRExpirable.expire(Instant)
instead- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(Date timestamp)
Description copied from interface:RExpirableAsync
UseRExpirableAsync.expireAsync(Instant)
instead- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireIfSet
public boolean expireIfSet(Duration duration)
Description copied from interface:RExpirable
Sets a timeout for this object only if it has been already set. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfSet
in interfaceRExpirable
- Parameters:
duration
- timeout before object will be deleted- Returns:
true
if the timeout was set andfalse
if not
-
expireIfSetAsync
public RFuture<Boolean> expireIfSetAsync(Duration duration)
- Specified by:
expireIfSetAsync
in interfaceRExpirableAsync
-
expireIfNotSet
public boolean expireIfNotSet(Duration duration)
Description copied from interface:RExpirable
Sets a timeout for this object only if it hasn't been set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfNotSet
in interfaceRExpirable
- Parameters:
duration
- timeout before object will be deleted- Returns:
true
if the timeout was set andfalse
if not
-
expireIfNotSetAsync
public RFuture<Boolean> expireIfNotSetAsync(Duration duration)
- Specified by:
expireIfNotSetAsync
in interfaceRExpirableAsync
-
expireIfGreater
public boolean expireIfGreater(Duration duration)
Description copied from interface:RExpirable
Sets a timeout for this object only if it's greater than timeout set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfGreater
in interfaceRExpirable
- Parameters:
duration
- timeout before object will be deleted- Returns:
true
if the timeout was set andfalse
if not
-
expireIfGreaterAsync
public RFuture<Boolean> expireIfGreaterAsync(Duration duration)
- Specified by:
expireIfGreaterAsync
in interfaceRExpirableAsync
-
expireIfLess
public boolean expireIfLess(Duration duration)
Description copied from interface:RExpirable
Sets a timeout for this object only if it's less than timeout set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfLess
in interfaceRExpirable
- Parameters:
duration
- timeout before object will be deleted- Returns:
true
if the timeout was set andfalse
if not
-
expireIfLessAsync
public RFuture<Boolean> expireIfLessAsync(Duration duration)
- Specified by:
expireIfLessAsync
in interfaceRExpirableAsync
-
clearExpire
public boolean clearExpire()
Description copied from interface:RExpirable
Clear an expire timeout or expire date for object.- Specified by:
clearExpire
in interfaceRExpirable
- Returns:
true
if timeout was removedfalse
if object does not exist or does not have an associated timeout
-
clearExpireAsync
public RFuture<Boolean> clearExpireAsync()
Description copied from interface:RExpirableAsync
Clear an expire timeout or expire date for object in async mode. Object will not be deleted.- Specified by:
clearExpireAsync
in interfaceRExpirableAsync
- Returns:
true
if the timeout was cleared andfalse
if not
-
remainTimeToLive
public long remainTimeToLive()
Description copied from interface:RExpirable
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLive
in interfaceRExpirable
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
remainTimeToLiveAsync
public RFuture<Long> remainTimeToLiveAsync()
Description copied from interface:RExpirableAsync
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsync
in interfaceRExpirableAsync
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
getExpireTime
public long getExpireTime()
Description copied from interface:RExpirable
Expiration time of Redisson object that has a timeoutRequires Redis 7.0.0 and higher.
- Specified by:
getExpireTime
in interfaceRExpirable
- Returns:
- expiration time
-
getExpireTimeAsync
public RFuture<Long> getExpireTimeAsync()
Description copied from interface:RExpirableAsync
Expiration time of Redisson object that has a timeoutRequires Redis 7.0.0 and higher.
- Specified by:
getExpireTimeAsync
in interfaceRExpirableAsync
- Returns:
- expiration time
-
expireAsync
protected RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys)
-
expireAtAsync
protected RFuture<Boolean> expireAtAsync(long timestamp, String param, String... keys)
-
-