Package org.redisson
Class RedissonBucket<V>
- java.lang.Object
-
- org.redisson.RedissonObject
-
- org.redisson.RedissonBucket<V>
-
- Type Parameters:
V- value type
- All Implemented Interfaces:
RBucket<V>,RBucketAsync<V>,RExpirable,RExpirableAsync,RObject,RObjectAsync
- Direct Known Subclasses:
RedissonBinaryStream,RedissonTransactionalBucket
public class RedissonBucket<V> extends RedissonObject implements RBucket<V>
- Author:
- Nikita Koksharov
-
-
Field Summary
-
Fields inherited from class org.redisson.RedissonObject
codec, commandExecutor, name
-
-
Constructor Summary
Constructors Constructor Description RedissonBucket(Codec codec, CommandAsyncExecutor connectionManager, String name)RedissonBucket(CommandAsyncExecutor connectionManager, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddListener(ObjectListener listener)Adds object event listenerRFuture<Integer>addListenerAsync(ObjectListener listener)Adds object event listenerbooleanclearExpire()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)booleancompareAndSet(V expect, V update)Atomically sets the value to the given updated value only if serialized state of the current value equals to serialized state of the expected value.RFuture<Boolean>compareAndSetAsync(V expect, V update)Atomically sets the value to the given updated value only if serialized state of the current value equals to serialized state of the expected value.booleanexpire(long timeToLive, TimeUnit timeUnit)Set a timeout for object.booleanexpire(Instant instant)Set an expire date for object.RFuture<Boolean>expireAsync(long timeToLive, TimeUnit timeUnit)Set a timeout for object in async mode.protected RFuture<Boolean>expireAsync(long timeToLive, TimeUnit timeUnit, String... keys)RFuture<Boolean>expireAsync(Instant instant)Set an expire date for object.booleanexpireAt(long timestamp)UseRExpirable.expire(Instant)insteadbooleanexpireAt(Date timestamp)UseRExpirable.expire(Instant)insteadRFuture<Boolean>expireAtAsync(long timestamp)UseRExpirableAsync.expireAsync(Instant)insteadprotected RFuture<Boolean>expireAtAsync(long timestamp, String... keys)RFuture<Boolean>expireAtAsync(Date timestamp)UseRExpirableAsync.expireAsync(Instant)insteadVget()Retrieves element stored in the holder.VgetAndDelete()Retrieves element in the holder and removes it.RFuture<V>getAndDeleteAsync()Retrieves element in the holder and removes it.VgetAndSet(V newValue)Retrieves current element in the holder and replaces it withnewValue.VgetAndSet(V value, long timeToLive, TimeUnit timeUnit)Retrieves current element in the holder and replaces it withnewValuewith definedtimeToLiveinterval.RFuture<V>getAndSetAsync(V newValue)Retrieves current element in the holder and replaces it withnewValue.RFuture<V>getAndSetAsync(V value, long timeToLive, TimeUnit timeUnit)Retrieves current element in the holder and replaces it withnewValuewith definedtimeToLiveinterval.RFuture<V>getAsync()Retrieves element stored in the holder.longremainTimeToLive()Remaining time to live of Redisson object that has a timeoutRFuture<Long>remainTimeToLiveAsync()Remaining time to live of Redisson object that has a timeoutvoidremoveListener(int listenerId)Removes object event listenerRFuture<Void>removeListenerAsync(int listenerId)Removes object event listenervoidset(V value)Stores element into the holder.voidset(V value, long timeToLive, TimeUnit timeUnit)Stores element into the holder with definedtimeToLiveinterval.voidsetAndKeepTTL(V value)Set value and keep existing TTL.RFuture<Void>setAndKeepTTLAsync(V value)Set value and keep existing TTL.RFuture<Void>setAsync(V value)Stores element into the holder.RFuture<Void>setAsync(V value, long timeToLive, TimeUnit timeUnit)Stores element into the holder with definedtimeToLiveinterval.booleansetIfExists(V value)Sets value only if it's already exists.booleansetIfExists(V value, long timeToLive, TimeUnit timeUnit)Sets value only if it's already exists.RFuture<Boolean>setIfExistsAsync(V value)Sets value only if it's already exists.RFuture<Boolean>setIfExistsAsync(V value, long timeToLive, TimeUnit timeUnit)Sets value only if it's already exists.longsize()Returns size of object in bytes.RFuture<Long>sizeAsync()Returns size of object in bytesbooleantrySet(V value)Tries to set element atomically into empty holder.booleantrySet(V value, long timeToLive, TimeUnit timeUnit)Tries to set element atomically into empty holder with definedtimeToLiveinterval.RFuture<Boolean>trySetAsync(V value)Tries to set element atomically into empty holder.RFuture<Boolean>trySetAsync(V value, long timeToLive, TimeUnit timeUnit)Tries to set element atomically into empty holder with definedtimeToLiveinterval.-
Methods inherited from class org.redisson.RedissonObject
addListener, 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, removeListenersAsync, 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, toString, wait, wait, wait
-
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expireAt, expireAt, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RObject
copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
-
-
-
Constructor Detail
-
RedissonBucket
public RedissonBucket(CommandAsyncExecutor connectionManager, String name)
-
RedissonBucket
public RedissonBucket(Codec codec, CommandAsyncExecutor connectionManager, String name)
-
-
Method Detail
-
compareAndSet
public boolean compareAndSet(V expect, V update)
Description copied from interface:RBucketAtomically sets the value to the given updated value only if serialized state of the current value equals to serialized state of the expected value.- Specified by:
compareAndSetin interfaceRBucket<V>- Parameters:
expect- the expected valueupdate- the new value- Returns:
trueif successful; orfalseif the actual value was not equal to the expected value.
-
compareAndSetAsync
public RFuture<Boolean> compareAndSetAsync(V expect, V update)
Description copied from interface:RBucketAsyncAtomically sets the value to the given updated value only if serialized state of the current value equals to serialized state of the expected value.- Specified by:
compareAndSetAsyncin interfaceRBucketAsync<V>- Parameters:
expect- the expected valueupdate- the new value- Returns:
trueif successful; orfalseif the actual value was not equal to the expected value.
-
getAndSet
public V getAndSet(V newValue)
Description copied from interface:RBucketRetrieves current element in the holder and replaces it withnewValue.
-
getAndSetAsync
public RFuture<V> getAndSetAsync(V newValue)
Description copied from interface:RBucketAsyncRetrieves current element in the holder and replaces it withnewValue.- Specified by:
getAndSetAsyncin interfaceRBucketAsync<V>- Parameters:
newValue- - value to set- Returns:
- previous value
-
get
public V get()
Description copied from interface:RBucketRetrieves element stored in the holder.
-
getAsync
public RFuture<V> getAsync()
Description copied from interface:RBucketAsyncRetrieves element stored in the holder.- Specified by:
getAsyncin interfaceRBucketAsync<V>- Returns:
- element
-
getAndDelete
public V getAndDelete()
Description copied from interface:RBucketRetrieves element in the holder and removes it.- Specified by:
getAndDeletein interfaceRBucket<V>- Returns:
- element
-
getAndDeleteAsync
public RFuture<V> getAndDeleteAsync()
Description copied from interface:RBucketAsyncRetrieves element in the holder and removes it.- Specified by:
getAndDeleteAsyncin interfaceRBucketAsync<V>- Returns:
- element
-
size
public long size()
Description copied from interface:RBucketReturns size of object in bytes.
-
sizeAsync
public RFuture<Long> sizeAsync()
Description copied from interface:RBucketAsyncReturns size of object in bytes- Specified by:
sizeAsyncin interfaceRBucketAsync<V>- Returns:
- object size
-
set
public void set(V value)
Description copied from interface:RBucketStores element into the holder.
-
setAsync
public RFuture<Void> setAsync(V value)
Description copied from interface:RBucketAsyncStores element into the holder.- Specified by:
setAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to set- Returns:
- void
-
set
public void set(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketStores element into the holder with definedtimeToLiveinterval.
-
setAsync
public RFuture<Void> setAsync(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketAsyncStores element into the holder with definedtimeToLiveinterval.- Specified by:
setAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to settimeToLive- - time to live intervaltimeUnit- - unit of time to live interval- Returns:
- void
-
trySetAsync
public RFuture<Boolean> trySetAsync(V value)
Description copied from interface:RBucketAsyncTries to set element atomically into empty holder.- Specified by:
trySetAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to set- Returns:
trueif successful, orfalseif element was already set
-
trySetAsync
public RFuture<Boolean> trySetAsync(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketAsyncTries to set element atomically into empty holder with definedtimeToLiveinterval.- Specified by:
trySetAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to settimeToLive- - time to live intervaltimeUnit- - unit of time to live interval- Returns:
trueif successful, orfalseif element was already set
-
trySet
public boolean trySet(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketTries to set element atomically into empty holder with definedtimeToLiveinterval.
-
trySet
public boolean trySet(V value)
Description copied from interface:RBucketTries to set element atomically into empty holder.
-
setIfExists
public boolean setIfExists(V value)
Description copied from interface:RBucketSets value only if it's already exists.- Specified by:
setIfExistsin interfaceRBucket<V>- Parameters:
value- - value to set- Returns:
trueif successful, orfalseif element wasn't set
-
setIfExistsAsync
public RFuture<Boolean> setIfExistsAsync(V value)
Description copied from interface:RBucketAsyncSets value only if it's already exists.- Specified by:
setIfExistsAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to set- Returns:
trueif successful, orfalseif element wasn't set
-
setAndKeepTTL
public void setAndKeepTTL(V value)
Description copied from interface:RBucketSet value and keep existing TTL.Requires Redis 6.0.0 and higher.
- Specified by:
setAndKeepTTLin interfaceRBucket<V>- Parameters:
value- - value to set
-
setAndKeepTTLAsync
public RFuture<Void> setAndKeepTTLAsync(V value)
Description copied from interface:RBucketAsyncSet value and keep existing TTL.Requires Redis 6.0.0 and higher.
- Specified by:
setAndKeepTTLAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to set- Returns:
- void
-
setIfExists
public boolean setIfExists(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketSets value only if it's already exists.- Specified by:
setIfExistsin interfaceRBucket<V>- Parameters:
value- - value to settimeToLive- - time to live intervaltimeUnit- - unit of time to live interval- Returns:
trueif successful, orfalseif element wasn't set
-
setIfExistsAsync
public RFuture<Boolean> setIfExistsAsync(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketAsyncSets value only if it's already exists.- Specified by:
setIfExistsAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to settimeToLive- - time to live intervaltimeUnit- - unit of time to live interval- Returns:
trueif successful, orfalseif element wasn't set
-
getAndSetAsync
public RFuture<V> getAndSetAsync(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketAsyncRetrieves current element in the holder and replaces it withnewValuewith definedtimeToLiveinterval.- Specified by:
getAndSetAsyncin interfaceRBucketAsync<V>- Parameters:
value- - value to settimeToLive- - time to live intervaltimeUnit- - unit of time to live interval- Returns:
- previous value
-
getAndSet
public V getAndSet(V value, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RBucketRetrieves current element in the holder and replaces it withnewValuewith definedtimeToLiveinterval.
-
addListener
public int addListener(ObjectListener listener)
Description copied from interface:RObjectAdds object event listener- Specified by:
addListenerin interfaceRBucket<V>- Specified by:
addListenerin interfaceRObject- Overrides:
addListenerin classRedissonObject- Parameters:
listener- - object event listener- Returns:
- listener id
- See Also:
ExpiredObjectListener,DeletedObjectListener
-
addListenerAsync
public RFuture<Integer> addListenerAsync(ObjectListener listener)
Description copied from interface:RObjectAsyncAdds object event listener- Specified by:
addListenerAsyncin interfaceRBucketAsync<V>- Specified by:
addListenerAsyncin interfaceRObjectAsync- Overrides:
addListenerAsyncin classRedissonObject- Parameters:
listener- - object event listener- Returns:
- listener id
- See Also:
ExpiredObjectListener,DeletedObjectListener
-
removeListener
public void removeListener(int listenerId)
Description copied from interface:RObjectRemoves object event listener- Specified by:
removeListenerin interfaceRObject- Overrides:
removeListenerin classRedissonObject- Parameters:
listenerId- - listener id
-
removeListenerAsync
public RFuture<Void> removeListenerAsync(int listenerId)
Description copied from interface:RObjectAsyncRemoves object event listener- Specified by:
removeListenerAsyncin interfaceRObjectAsync- Overrides:
removeListenerAsyncin classRedissonObject- Parameters:
listenerId- - listener id
-
expire
public boolean expire(long timeToLive, TimeUnit timeUnit)Description copied from interface:RExpirableSet a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expirein interfaceRExpirable- Parameters:
timeToLive- - timeout before object will be deletedtimeUnit- - timeout time unit- Returns:
trueif the timeout was set andfalseif not
-
expireAsync
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirableAsyncSet a timeout for object in async mode. After the timeout has expired, the key will automatically be deleted.- Specified by:
expireAsyncin interfaceRExpirableAsync- Parameters:
timeToLive- - timeout before object will be deletedtimeUnit- - timeout time unit- Returns:
trueif the timeout was set andfalseif not
-
expireAt
public boolean expireAt(long timestamp)
Description copied from interface:RExpirableUseRExpirable.expire(Instant)instead- Specified by:
expireAtin interfaceRExpirable- Parameters:
timestamp- - expire date in milliseconds (Unix timestamp)- Returns:
trueif the timeout was set andfalseif not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(long timestamp)
Description copied from interface:RExpirableAsyncUseRExpirableAsync.expireAsync(Instant)instead- Specified by:
expireAtAsyncin interfaceRExpirableAsync- Parameters:
timestamp- - expire date in milliseconds (Unix timestamp)- Returns:
trueif the timeout was set andfalseif not
-
expire
public boolean expire(Instant instant)
Description copied from interface:RExpirableSet an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expirein interfaceRExpirable- Parameters:
instant- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAsync
public RFuture<Boolean> expireAsync(Instant instant)
Description copied from interface:RExpirableAsyncSet an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAsyncin interfaceRExpirableAsync- Parameters:
instant- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAt
public boolean expireAt(Date timestamp)
Description copied from interface:RExpirableUseRExpirable.expire(Instant)instead- Specified by:
expireAtin interfaceRExpirable- Parameters:
timestamp- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(Date timestamp)
Description copied from interface:RExpirableAsyncUseRExpirableAsync.expireAsync(Instant)instead- Specified by:
expireAtAsyncin interfaceRExpirableAsync- Parameters:
timestamp- - expire date- Returns:
trueif the timeout was set andfalseif not
-
clearExpire
public boolean clearExpire()
Description copied from interface:RExpirableClear an expire timeout or expire date for object.- Specified by:
clearExpirein interfaceRExpirable- Returns:
trueif timeout was removedfalseif object does not exist or does not have an associated timeout
-
clearExpireAsync
public RFuture<Boolean> clearExpireAsync()
Description copied from interface:RExpirableAsyncClear an expire timeout or expire date for object in async mode. Object will not be deleted.- Specified by:
clearExpireAsyncin interfaceRExpirableAsync- Returns:
trueif the timeout was cleared andfalseif not
-
remainTimeToLive
public long remainTimeToLive()
Description copied from interface:RExpirableRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLivein 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:RExpirableAsyncRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsyncin interfaceRExpirableAsync- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
expireAsync
protected RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String... keys)
-
-