Package org.redisson
Class RedissonObject
- java.lang.Object
-
- org.redisson.RedissonObject
-
- All Implemented Interfaces:
RObject,RObjectAsync
- Direct Known Subclasses:
JCache,RedissonAtomicDouble,RedissonAtomicLong,RedissonBaseAdder,RedissonBaseLock,RedissonBitSet,RedissonBloomFilter,RedissonBucket,RedissonCountDownLatch,RedissonDelayedQueue,RedissonHyperLogLog,RedissonIdGenerator,RedissonList,RedissonListMultimapValues,RedissonMap,RedissonMultimap,RedissonPermitExpirableSemaphore,RedissonRateLimiter,RedissonReadWriteLock,RedissonReliableTopic,RedissonScoredSortedSet,RedissonSemaphore,RedissonSet,RedissonSetCache,RedissonSetMultimapValues,RedissonSortedSet,RedissonStream,RedissonTimeSeries,RedissonTransferQueue
public abstract class RedissonObject extends Object implements RObject
Base Redisson object- Author:
- Nikita Koksharov
-
-
Field Summary
Fields Modifier and Type Field Description protected Codeccodecprotected CommandAsyncExecutorcommandExecutorprotected Stringname
-
Constructor Summary
Constructors Constructor Description RedissonObject(Codec codec, CommandAsyncExecutor commandExecutor, String name)RedissonObject(CommandAsyncExecutor commandExecutor, String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T extends ObjectListener>
intaddListener(String name, T listener, BiConsumer<T,String> consumer)intaddListener(ObjectListener listener)Adds object event listenerprotected <T extends ObjectListener>
RFuture<Integer>addListenerAsync(String name, T listener, BiConsumer<T,String> consumer)RFuture<Integer>addListenerAsync(ObjectListener listener)Adds object event listenervoidcopy(String host, int port, int database, long timeout)Copy object from source Redis instance to destination Redis instanceRFuture<Void>copyAsync(String host, int port, int database, long timeout)Copy object from source Redis instance to destination Redis instance in async modebooleandelete()Deletes the objectRFuture<Boolean>deleteAsync()Delete object in async modeprotected RFuture<Boolean>deleteAsync(String... keys)byte[]dump()Returns dump of objectRFuture<byte[]>dumpAsync()Returns dump of objectio.netty.buffer.ByteBufencode(Object value)protected List<io.netty.buffer.ByteBuf>encode(Object... values)protected List<io.netty.buffer.ByteBuf>encode(Collection<?> values)voidencode(Collection<Object> params, Collection<?> values)io.netty.buffer.ByteBufencodeMapKey(Object value)protected voidencodeMapKeys(Collection<Object> params, Collection<?> values)io.netty.buffer.ByteBufencodeMapValue(Object value)protected voidencodeMapValues(Collection<Object> params, Collection<?> values)protected <V> Vget(RFuture<V> future)CodecgetCodec()Returns the underlying Codec used by this RObjectLonggetIdleTime()Returns number of seconds spent since last write or read operation over this object.RFuture<Long>getIdleTimeAsync()Returns number of seconds spent since last write or read operation over this object.StringgetLockByMapKey(Object key, String suffix)StringgetLockByValue(Object key, String suffix)StringgetName()Returns name of objectStringgetRawName()protected StringgetRawName(Object o)booleanisExists()Check object existenceRFuture<Boolean>isExistsAsync()Check object existence in async mode.voidmigrate(String host, int port, int database, long timeout)Copy object from source Redis instance to destination Redis instanceRFuture<Void>migrateAsync(String host, int port, int database, long timeout)Transfer object from source Redis instance to destination Redis instance in async modebooleanmove(int database)Move object to another databaseRFuture<Boolean>moveAsync(int database)Move object to another database in async modestatic StringprefixName(String prefix, String name)voidremoveListener(int listenerId)Removes object event listenerRFuture<Void>removeListenerAsync(int listenerId)Removes object event listenerprotected voidremoveListenersAsync(int listenerId, CountableListener<Void> listener)voidrename(String newName)Rename current object key tonewNameRFuture<Void>renameAsync(String newName)Rename current object key tonewNamein async modebooleanrenamenx(String newName)Rename current object key tonewNameonly if new key is not existsRFuture<Boolean>renamenxAsync(String newName)Rename current object key tonewNamein async mode only if new key is not existsvoidrestore(byte[] state)Restores object using its state returned byRObject.dump()method.voidrestore(byte[] state, long timeToLive, TimeUnit timeUnit)Restores object using its state returned byRObject.dump()method and set time to live for it.voidrestoreAndReplace(byte[] state)Restores and replaces object if it already exists.voidrestoreAndReplace(byte[] state, long timeToLive, TimeUnit timeUnit)Restores and replaces object if it already exists and set time to live for it.RFuture<Void>restoreAndReplaceAsync(byte[] state)Restores and replaces object if it already exists.RFuture<Void>restoreAndReplaceAsync(byte[] state, long timeToLive, TimeUnit timeUnit)Restores and replaces object if it already exists and set time to live for it.RFuture<Void>restoreAsync(byte[] state)Restores object using its state returned byRObjectAsync.dumpAsync()method.RFuture<Void>restoreAsync(byte[] state, long timeToLive, TimeUnit timeUnit)Restores object using its state returned byRObjectAsync.dumpAsync()method and set time to live for it.protected voidsetName(String name)longsizeInMemory()Returns bytes amount used by object in Redis memory.RFuture<Long>sizeInMemoryAsync()Returns bytes amount used by object in Redis memory.RFuture<Long>sizeInMemoryAsync(List<Object> keys)RFuture<Long>sizeInMemoryAsync(CommandAsyncExecutor commandExecutor, List<Object> keys)static StringsuffixName(String name, String suffix)protected longtoSeconds(long timeout, TimeUnit unit)protected <T> Stream<T>toStream(Iterator<T> iterator)booleantouch()Update the last access time of an object.RFuture<Boolean>touchAsync()Update the last access time of an object in async mode.booleanunlink()Delete the objects.RFuture<Boolean>unlinkAsync()Delete the objects.
-
-
-
Field Detail
-
commandExecutor
protected final CommandAsyncExecutor commandExecutor
-
name
protected String name
-
codec
protected final Codec codec
-
-
Constructor Detail
-
RedissonObject
public RedissonObject(Codec codec, CommandAsyncExecutor commandExecutor, String name)
-
RedissonObject
public RedissonObject(CommandAsyncExecutor commandExecutor, String name)
-
-
Method Detail
-
get
protected final <V> V get(RFuture<V> future)
-
toSeconds
protected final long toSeconds(long timeout, TimeUnit unit)
-
getRawName
public final String getRawName()
-
setName
protected final void setName(String name)
-
rename
public void rename(String newName)
Description copied from interface:RObjectRename current object key tonewName
-
sizeInMemoryAsync
public RFuture<Long> sizeInMemoryAsync()
Description copied from interface:RObjectAsyncReturns bytes amount used by object in Redis memory.- Specified by:
sizeInMemoryAsyncin interfaceRObjectAsync- Returns:
- size in bytes
-
sizeInMemoryAsync
public final RFuture<Long> sizeInMemoryAsync(CommandAsyncExecutor commandExecutor, List<Object> keys)
-
sizeInMemory
public long sizeInMemory()
Description copied from interface:RObjectReturns bytes amount used by object in Redis memory.- Specified by:
sizeInMemoryin interfaceRObject- Returns:
- size in bytes
-
renameAsync
public RFuture<Void> renameAsync(String newName)
Description copied from interface:RObjectAsyncRename current object key tonewNamein async mode- Specified by:
renameAsyncin interfaceRObjectAsync- Parameters:
newName- - new name of object- Returns:
- void
-
migrate
public void migrate(String host, int port, int database, long timeout)
Description copied from interface:RObjectCopy object from source Redis instance to destination Redis instance
-
migrateAsync
public RFuture<Void> migrateAsync(String host, int port, int database, long timeout)
Description copied from interface:RObjectAsyncTransfer object from source Redis instance to destination Redis instance in async mode- Specified by:
migrateAsyncin interfaceRObjectAsync- Parameters:
host- - destination hostport- - destination portdatabase- - destination databasetimeout- - maximum idle time in any moment of the communication with the destination instance in milliseconds- Returns:
- void
-
copy
public void copy(String host, int port, int database, long timeout)
Description copied from interface:RObjectCopy object from source Redis instance to destination Redis instance
-
copyAsync
public RFuture<Void> copyAsync(String host, int port, int database, long timeout)
Description copied from interface:RObjectAsyncCopy object from source Redis instance to destination Redis instance in async mode- Specified by:
copyAsyncin interfaceRObjectAsync- Parameters:
host- - destination hostport- - destination portdatabase- - destination databasetimeout- - maximum idle time in any moment of the communication with the destination instance in milliseconds- Returns:
- void
-
move
public boolean move(int database)
Description copied from interface:RObjectMove object to another database
-
moveAsync
public RFuture<Boolean> moveAsync(int database)
Description copied from interface:RObjectAsyncMove object to another database in async mode- Specified by:
moveAsyncin interfaceRObjectAsync- Parameters:
database- - number of Redis database- Returns:
trueif key was movedfalseif not
-
renamenx
public boolean renamenx(String newName)
Description copied from interface:RObjectRename current object key tonewNameonly if new key is not exists
-
renamenxAsync
public RFuture<Boolean> renamenxAsync(String newName)
Description copied from interface:RObjectAsyncRename current object key tonewNamein async mode only if new key is not exists- Specified by:
renamenxAsyncin interfaceRObjectAsync- Parameters:
newName- - new name of object- Returns:
trueif object has been renamed successfully andfalseotherwise
-
delete
public boolean delete()
Description copied from interface:RObjectDeletes the object
-
deleteAsync
public RFuture<Boolean> deleteAsync()
Description copied from interface:RObjectAsyncDelete object in async mode- Specified by:
deleteAsyncin interfaceRObjectAsync- Returns:
trueif object was deletedfalseif not
-
unlink
public boolean unlink()
Description copied from interface:RObjectDelete the objects. Actual removal will happen later asynchronously.Requires Redis 4.0+
-
unlinkAsync
public RFuture<Boolean> unlinkAsync()
Description copied from interface:RObjectAsyncDelete the objects. Actual removal will happen later asynchronously.Requires Redis 4.0+
- Specified by:
unlinkAsyncin interfaceRObjectAsync- Returns:
trueif it was exist and deleted elsefalse
-
touch
public boolean touch()
Description copied from interface:RObjectUpdate the last access time of an object.
-
touchAsync
public RFuture<Boolean> touchAsync()
Description copied from interface:RObjectAsyncUpdate the last access time of an object in async mode.- Specified by:
touchAsyncin interfaceRObjectAsync- Returns:
trueif object was touched elsefalse
-
isExists
public boolean isExists()
Description copied from interface:RObjectCheck object existence
-
isExistsAsync
public RFuture<Boolean> isExistsAsync()
Description copied from interface:RObjectAsyncCheck object existence in async mode.- Specified by:
isExistsAsyncin interfaceRObjectAsync- Returns:
trueif object exists andfalseotherwise
-
getCodec
public Codec getCodec()
Description copied from interface:RObjectReturns the underlying Codec used by this RObject
-
encode
protected List<io.netty.buffer.ByteBuf> encode(Collection<?> values)
-
encode
public void encode(Collection<Object> params, Collection<?> values)
-
encodeMapKeys
protected void encodeMapKeys(Collection<Object> params, Collection<?> values)
-
encodeMapValues
protected void encodeMapValues(Collection<Object> params, Collection<?> values)
-
encode
public io.netty.buffer.ByteBuf encode(Object value)
-
encodeMapKey
public io.netty.buffer.ByteBuf encodeMapKey(Object value)
-
encodeMapValue
public io.netty.buffer.ByteBuf encodeMapValue(Object value)
-
dump
public byte[] dump()
Description copied from interface:RObjectReturns dump of object
-
dumpAsync
public RFuture<byte[]> dumpAsync()
Description copied from interface:RObjectAsyncReturns dump of object- Specified by:
dumpAsyncin interfaceRObjectAsync- Returns:
- dump
-
restore
public void restore(byte[] state)
Description copied from interface:RObjectRestores object using its state returned byRObject.dump()method.
-
restoreAsync
public RFuture<Void> restoreAsync(byte[] state)
Description copied from interface:RObjectAsyncRestores object using its state returned byRObjectAsync.dumpAsync()method.- Specified by:
restoreAsyncin interfaceRObjectAsync- Parameters:
state- - state of object- Returns:
- void
-
restore
public void restore(byte[] state, long timeToLive, TimeUnit timeUnit)Description copied from interface:RObjectRestores object using its state returned byRObject.dump()method and set time to live for it.
-
restoreAsync
public RFuture<Void> restoreAsync(byte[] state, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RObjectAsyncRestores object using its state returned byRObjectAsync.dumpAsync()method and set time to live for it.- Specified by:
restoreAsyncin interfaceRObjectAsync- Parameters:
state- - state of objecttimeToLive- - time to live of the objecttimeUnit- - time unit- Returns:
- void
-
restoreAndReplace
public void restoreAndReplace(byte[] state, long timeToLive, TimeUnit timeUnit)Description copied from interface:RObjectRestores and replaces object if it already exists and set time to live for it.- Specified by:
restoreAndReplacein interfaceRObject- Parameters:
state- - state of the objecttimeToLive- - time to live of the objecttimeUnit- - time unit
-
restoreAndReplaceAsync
public RFuture<Void> restoreAndReplaceAsync(byte[] state, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RObjectAsyncRestores and replaces object if it already exists and set time to live for it.- Specified by:
restoreAndReplaceAsyncin interfaceRObjectAsync- Parameters:
state- - state of the objecttimeToLive- - time to live of the objecttimeUnit- - time unit- Returns:
- void
-
restoreAndReplace
public void restoreAndReplace(byte[] state)
Description copied from interface:RObjectRestores and replaces object if it already exists.- Specified by:
restoreAndReplacein interfaceRObject- Parameters:
state- - state of the object
-
restoreAndReplaceAsync
public RFuture<Void> restoreAndReplaceAsync(byte[] state)
Description copied from interface:RObjectAsyncRestores and replaces object if it already exists.- Specified by:
restoreAndReplaceAsyncin interfaceRObjectAsync- Parameters:
state- - state of the object- Returns:
- void
-
getIdleTime
public Long getIdleTime()
Description copied from interface:RObjectReturns number of seconds spent since last write or read operation over this object.- Specified by:
getIdleTimein interfaceRObject- Returns:
- number of seconds
-
getIdleTimeAsync
public RFuture<Long> getIdleTimeAsync()
Description copied from interface:RObjectAsyncReturns number of seconds spent since last write or read operation over this object.- Specified by:
getIdleTimeAsyncin interfaceRObjectAsync- Returns:
- number of seconds
-
addListener
protected final <T extends ObjectListener> int addListener(String name, T listener, BiConsumer<T,String> consumer)
-
addListenerAsync
protected final <T extends ObjectListener> RFuture<Integer> addListenerAsync(String name, T listener, BiConsumer<T,String> consumer)
-
addListener
public int addListener(ObjectListener listener)
Description copied from interface:RObjectAdds object event listener- Specified by:
addListenerin interfaceRObject- 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 interfaceRObjectAsync- 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- Parameters:
listenerId- - listener id
-
removeListenerAsync
public RFuture<Void> removeListenerAsync(int listenerId)
Description copied from interface:RObjectAsyncRemoves object event listener- Specified by:
removeListenerAsyncin interfaceRObjectAsync- Parameters:
listenerId- - listener id
-
removeListenersAsync
protected final void removeListenersAsync(int listenerId, CountableListener<Void> listener)
-
-