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 Codec
codec
protected CommandAsyncExecutor
commandExecutor
protected String
name
-
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)
int
addListener(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 listenervoid
copy(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 modeboolean
delete()
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.ByteBuf
encode(Object value)
protected List<io.netty.buffer.ByteBuf>
encode(Object... values)
protected List<io.netty.buffer.ByteBuf>
encode(Collection<?> values)
void
encode(Collection<Object> params, Collection<?> values)
io.netty.buffer.ByteBuf
encodeMapKey(Object value)
protected void
encodeMapKeys(Collection<Object> params, Collection<?> values)
io.netty.buffer.ByteBuf
encodeMapValue(Object value)
protected void
encodeMapValues(Collection<Object> params, Collection<?> values)
protected <V> V
get(RFuture<V> future)
Codec
getCodec()
Returns the underlying Codec used by this RObjectLong
getIdleTime()
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.String
getLockByMapKey(Object key, String suffix)
String
getLockByValue(Object key, String suffix)
String
getName()
Returns name of objectString
getRawName()
protected String
getRawName(Object o)
boolean
isExists()
Check object existenceRFuture<Boolean>
isExistsAsync()
Check object existence in async mode.void
migrate(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 modeboolean
move(int database)
Move object to another databaseRFuture<Boolean>
moveAsync(int database)
Move object to another database in async modestatic String
prefixName(String prefix, String name)
void
removeListener(int listenerId)
Removes object event listenerRFuture<Void>
removeListenerAsync(int listenerId)
Removes object event listenervoid
rename(String newName)
Rename current object key tonewName
RFuture<Void>
renameAsync(String newName)
Rename current object key tonewName
in async modeboolean
renamenx(String newName)
Rename current object key tonewName
only if new key is not existsRFuture<Boolean>
renamenxAsync(String newName)
Rename current object key tonewName
in async mode only if new key is not existsvoid
restore(byte[] state)
Restores object using its state returned byRObject.dump()
method.void
restore(byte[] state, long timeToLive, TimeUnit timeUnit)
Restores object using its state returned byRObject.dump()
method and set time to live for it.void
restoreAndReplace(byte[] state)
Restores and replaces object if it already exists.void
restoreAndReplace(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 void
setName(String name)
long
sizeInMemory()
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 String
suffixName(String name, String suffix)
protected long
toSeconds(long timeout, TimeUnit unit)
protected <T> Stream<T>
toStream(Iterator<T> iterator)
boolean
touch()
Update the last access time of an object.RFuture<Boolean>
touchAsync()
Update the last access time of an object in async mode.boolean
unlink()
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:RObject
Rename current object key tonewName
-
sizeInMemoryAsync
public RFuture<Long> sizeInMemoryAsync()
Description copied from interface:RObjectAsync
Returns bytes amount used by object in Redis memory.- Specified by:
sizeInMemoryAsync
in interfaceRObjectAsync
- Returns:
- size in bytes
-
sizeInMemoryAsync
public final RFuture<Long> sizeInMemoryAsync(CommandAsyncExecutor commandExecutor, List<Object> keys)
-
sizeInMemory
public long sizeInMemory()
Description copied from interface:RObject
Returns bytes amount used by object in Redis memory.- Specified by:
sizeInMemory
in interfaceRObject
- Returns:
- size in bytes
-
renameAsync
public RFuture<Void> renameAsync(String newName)
Description copied from interface:RObjectAsync
Rename current object key tonewName
in async mode- Specified by:
renameAsync
in 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:RObject
Copy 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:RObjectAsync
Transfer object from source Redis instance to destination Redis instance in async mode- Specified by:
migrateAsync
in 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:RObject
Copy 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:RObjectAsync
Copy object from source Redis instance to destination Redis instance in async mode- Specified by:
copyAsync
in 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:RObject
Move object to another database
-
moveAsync
public RFuture<Boolean> moveAsync(int database)
Description copied from interface:RObjectAsync
Move object to another database in async mode- Specified by:
moveAsync
in interfaceRObjectAsync
- Parameters:
database
- - number of Redis database- Returns:
true
if key was movedfalse
if not
-
renamenx
public boolean renamenx(String newName)
Description copied from interface:RObject
Rename current object key tonewName
only if new key is not exists
-
renamenxAsync
public RFuture<Boolean> renamenxAsync(String newName)
Description copied from interface:RObjectAsync
Rename current object key tonewName
in async mode only if new key is not exists- Specified by:
renamenxAsync
in interfaceRObjectAsync
- Parameters:
newName
- - new name of object- Returns:
true
if object has been renamed successfully andfalse
otherwise
-
delete
public boolean delete()
Description copied from interface:RObject
Deletes the object
-
deleteAsync
public RFuture<Boolean> deleteAsync()
Description copied from interface:RObjectAsync
Delete object in async mode- Specified by:
deleteAsync
in interfaceRObjectAsync
- Returns:
true
if object was deletedfalse
if not
-
unlink
public boolean unlink()
Description copied from interface:RObject
Delete the objects. Actual removal will happen later asynchronously.Requires Redis 4.0+
-
unlinkAsync
public RFuture<Boolean> unlinkAsync()
Description copied from interface:RObjectAsync
Delete the objects. Actual removal will happen later asynchronously.Requires Redis 4.0+
- Specified by:
unlinkAsync
in interfaceRObjectAsync
- Returns:
true
if it was exist and deleted elsefalse
-
touch
public boolean touch()
Description copied from interface:RObject
Update the last access time of an object.
-
touchAsync
public RFuture<Boolean> touchAsync()
Description copied from interface:RObjectAsync
Update the last access time of an object in async mode.- Specified by:
touchAsync
in interfaceRObjectAsync
- Returns:
true
if object was touched elsefalse
-
isExists
public boolean isExists()
Description copied from interface:RObject
Check object existence
-
isExistsAsync
public RFuture<Boolean> isExistsAsync()
Description copied from interface:RObjectAsync
Check object existence in async mode.- Specified by:
isExistsAsync
in interfaceRObjectAsync
- Returns:
true
if object exists andfalse
otherwise
-
getCodec
public Codec getCodec()
Description copied from interface:RObject
Returns 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:RObject
Returns dump of object
-
dumpAsync
public RFuture<byte[]> dumpAsync()
Description copied from interface:RObjectAsync
Returns dump of object- Specified by:
dumpAsync
in interfaceRObjectAsync
- Returns:
- dump
-
restore
public void restore(byte[] state)
Description copied from interface:RObject
Restores object using its state returned byRObject.dump()
method.
-
restoreAsync
public RFuture<Void> restoreAsync(byte[] state)
Description copied from interface:RObjectAsync
Restores object using its state returned byRObjectAsync.dumpAsync()
method.- Specified by:
restoreAsync
in interfaceRObjectAsync
- Parameters:
state
- - state of object- Returns:
- void
-
restore
public void restore(byte[] state, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RObject
Restores 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:RObjectAsync
Restores object using its state returned byRObjectAsync.dumpAsync()
method and set time to live for it.- Specified by:
restoreAsync
in 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:RObject
Restores and replaces object if it already exists and set time to live for it.- Specified by:
restoreAndReplace
in 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:RObjectAsync
Restores and replaces object if it already exists and set time to live for it.- Specified by:
restoreAndReplaceAsync
in 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:RObject
Restores and replaces object if it already exists.- Specified by:
restoreAndReplace
in interfaceRObject
- Parameters:
state
- - state of the object
-
restoreAndReplaceAsync
public RFuture<Void> restoreAndReplaceAsync(byte[] state)
Description copied from interface:RObjectAsync
Restores and replaces object if it already exists.- Specified by:
restoreAndReplaceAsync
in interfaceRObjectAsync
- Parameters:
state
- - state of the object- Returns:
- void
-
getIdleTime
public Long getIdleTime()
Description copied from interface:RObject
Returns number of seconds spent since last write or read operation over this object.- Specified by:
getIdleTime
in interfaceRObject
- Returns:
- number of seconds
-
getIdleTimeAsync
public RFuture<Long> getIdleTimeAsync()
Description copied from interface:RObjectAsync
Returns number of seconds spent since last write or read operation over this object.- Specified by:
getIdleTimeAsync
in 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:RObject
Adds object event listener- Specified by:
addListener
in interfaceRObject
- Parameters:
listener
- - object event listener- Returns:
- listener id
- See Also:
ExpiredObjectListener
,DeletedObjectListener
-
addListenerAsync
public RFuture<Integer> addListenerAsync(ObjectListener listener)
Description copied from interface:RObjectAsync
Adds object event listener- Specified by:
addListenerAsync
in interfaceRObjectAsync
- Parameters:
listener
- - object event listener- Returns:
- listener id
- See Also:
ExpiredObjectListener
,DeletedObjectListener
-
removeListener
public void removeListener(int listenerId)
Description copied from interface:RObject
Removes object event listener- Specified by:
removeListener
in interfaceRObject
- Parameters:
listenerId
- - listener id
-
removeListenerAsync
public RFuture<Void> removeListenerAsync(int listenerId)
Description copied from interface:RObjectAsync
Removes object event listener- Specified by:
removeListenerAsync
in interfaceRObjectAsync
- Parameters:
listenerId
- - listener id
-
-