Class RedissonKeys
- java.lang.Object
-
- org.redisson.RedissonKeys
-
- All Implemented Interfaces:
RKeys,RKeysAsync
public class RedissonKeys extends Object implements RKeys
- Author:
- Nikita Koksharov
-
-
Constructor Summary
Constructors Constructor Description RedissonKeys(CommandAsyncExecutor commandExecutor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanclearExpire(String name)Clear an expire timeout or expire date for object.RFuture<Boolean>clearExpireAsync(String name)Clear an expire timeout or expire date for object.voidcopy(String name, String host, int port, int database, long timeout)Copy object from source Redis instance to destination Redis instanceRFuture<Void>copyAsync(String name, String host, int port, int database, long timeout)Copy object from source Redis instance to destination Redis instance in async modelongcount()Returns the number of keys in the currently-selected databaseRFuture<Long>countAsync()Returns the number of keys in the currently-selected database in async modelongcountExists(String... names)Checks if provided keys existRFuture<Long>countExistsAsync(String... names)Checks if provided keys existlongdelete(String... keys)Delete multiple objects by namelongdelete(RObject... objects)Delete multiple objectsRFuture<Long>deleteAsync(String... keys)Delete multiple objects by nameRFuture<Long>deleteAsync(RObject... objects)Delete multiple objectslongdeleteByPattern(String pattern)Delete multiple objects by a key pattern.RFuture<Long>deleteByPatternAsync(String pattern)Delete multiple objects by a key pattern.booleanexpire(String name, long timeToLive, TimeUnit timeUnit)Set a timeout for object.RFuture<Boolean>expireAsync(String name, long timeToLive, TimeUnit timeUnit)Set a timeout for object.booleanexpireAt(String name, long timestamp)Set an expire date for object.RFuture<Boolean>expireAtAsync(String name, long timestamp)Set an expire date for object.voidflushall()Delete all keys of all existing databasesRFuture<Void>flushallAsync()Delete all keys of all existing databasesvoidflushallParallel()Delete all keys of all existing databases in background without blocking server.RFuture<Void>flushallParallelAsync()Delete all keys of all existing databases in background without blocking server.voidflushdb()Delete all keys of currently selected databaseRFuture<Void>flushdbAsync()Delete all keys of currently selected databasevoidflushdbParallel()Delete all keys of currently selected database in background without blocking server.RFuture<Void>flushdbParallelAsync()Delete all keys of currently selected database in background without blocking server.CommandAsyncExecutorgetCommandExecutor()ConnectionManagergetConnectionManager()Iterable<String>getKeys()Get all keys using iterator.Iterable<String>getKeys(int count)Get all keys using iterator.Iterable<String>getKeysByPattern(String pattern)Get all keys by pattern using iterator.Iterable<String>getKeysByPattern(String pattern, int count)Get all keys by pattern using iterator.<T> Iterable<T>getKeysByPattern(RedisCommand<?> command, String pattern, int limit, int count)Stream<String>getKeysStream()Get all keys using Stream.Stream<String>getKeysStream(int count)Get all keys using Stream.Stream<String>getKeysStreamByPattern(String pattern)Get all keys by pattern using Stream.Stream<String>getKeysStreamByPattern(String pattern, int count)Get all keys by pattern using Stream.Iterable<String>getKeysWithLimit(int limit)Get keys using iterator with definedlimit.Iterable<String>getKeysWithLimit(String pattern, int limit)Get keys using iterator with definedlimit.intgetSlot(String key)Get hash slot identifier for key.RFuture<Integer>getSlotAsync(String key)Get hash slot identifier for key in async mode.RTypegetType(String key)Get Redis object type by keyRFuture<RType>getTypeAsync(String key)Get Redis object type by keyvoidmigrate(String name, String host, int port, int database, long timeout)Transfer object from source Redis instance to destination Redis instanceRFuture<Void>migrateAsync(String name, String host, int port, int database, long timeout)Transfer object from source Redis instance to destination Redis instancebooleanmove(String name, int database)Move object to another databaseRFuture<Boolean>moveAsync(String name, int database)Move object to another databaseStringrandomKey()Get random keyRFuture<String>randomKeyAsync()Get random key in async modelongremainTimeToLive(String name)Remaining time to live of Redisson object that has a timeoutRFuture<Long>remainTimeToLiveAsync(String name)Remaining time to live of Redisson object that has a timeoutvoidrename(String currentName, String newName)Rename current object key tonewNameRFuture<Void>renameAsync(String currentName, String newName)Rename current object key tonewNamebooleanrenamenx(String oldName, String newName)Rename object witholdNametonewNameonly if new key is not existsRFuture<Boolean>renamenxAsync(String oldName, String newName)Rename object witholdNametonewNameonly if new key is not existsRFuture<ScanResult<Object>>scanIteratorAsync(RedisClient client, MasterSlaveEntry entry, long startPos, String pattern, int count)RFuture<ScanResult<Object>>scanIteratorAsync(RedisClient client, MasterSlaveEntry entry, RedisCommand<?> command, long startPos, String pattern, int count)voidswapdb(int db1, int db2)Swap two databases.RFuture<Void>swapdbAsync(int db1, int db2)Swap two databases.protected <T> Stream<T>toStream(Iterator<T> iterator)longtouch(String... names)Update the last access time of an object.RFuture<Long>touchAsync(String... names)Update the last access time of an object.longunlink(String... keys)Delete multiple objects by name.RFuture<Long>unlinkAsync(String... keys)Delete multiple objects by name.
-
-
-
Constructor Detail
-
RedissonKeys
public RedissonKeys(CommandAsyncExecutor commandExecutor)
-
-
Method Detail
-
getCommandExecutor
public CommandAsyncExecutor getCommandExecutor()
-
getConnectionManager
public ConnectionManager getConnectionManager()
-
getType
public RType getType(String key)
Description copied from interface:RKeysGet Redis object type by key
-
getTypeAsync
public RFuture<RType> getTypeAsync(String key)
Description copied from interface:RKeysAsyncGet Redis object type by key- Specified by:
getTypeAsyncin interfaceRKeysAsync- Parameters:
key- - name of key- Returns:
- type of key
-
getSlot
public int getSlot(String key)
Description copied from interface:RKeysGet hash slot identifier for key. Available for cluster nodes only
-
getSlotAsync
public RFuture<Integer> getSlotAsync(String key)
Description copied from interface:RKeysAsyncGet hash slot identifier for key in async mode. Available for cluster nodes only- Specified by:
getSlotAsyncin interfaceRKeysAsync- Parameters:
key- - name of key- Returns:
- slot
-
getKeysByPattern
public Iterable<String> getKeysByPattern(String pattern)
Description copied from interface:RKeysGet all keys by pattern using iterator. Keys traversed with SCAN operation. Each SCAN operation loads up to 10 keys per request.Supported glob-style patterns:
h?llo subscribes to hello, hallo and hxllo
h*llo subscribes to hllo and heeeello
h[ae]llo subscribes to hello and hallo, but not hillo
- Specified by:
getKeysByPatternin interfaceRKeys- Parameters:
pattern- - match pattern- Returns:
- Iterable object
-
getKeysByPattern
public Iterable<String> getKeysByPattern(String pattern, int count)
Description copied from interface:RKeysGet all keys by pattern using iterator. Keys traversed with SCAN operation. Each SCAN operation loads up tocountkeys per request.Supported glob-style patterns:
h?llo subscribes to hello, hallo and hxllo
h*llo subscribes to hllo and heeeello
h[ae]llo subscribes to hello and hallo, but not hillo
- Specified by:
getKeysByPatternin interfaceRKeys- Parameters:
pattern- - match patterncount- - keys loaded per request to Redis- Returns:
- Iterable object
-
getKeysByPattern
public <T> Iterable<T> getKeysByPattern(RedisCommand<?> command, String pattern, int limit, int count)
-
getKeysWithLimit
public Iterable<String> getKeysWithLimit(int limit)
Description copied from interface:RKeysGet keys using iterator with definedlimit. Keys are traversed with SCAN operation.- Specified by:
getKeysWithLimitin interfaceRKeys- Parameters:
limit- - limit of keys amount- Returns:
- Iterable object
-
getKeysWithLimit
public Iterable<String> getKeysWithLimit(String pattern, int limit)
Description copied from interface:RKeysGet keys using iterator with definedlimit. Keys are traversed with SCAN operation.Supported glob-style patterns:
h?llo subscribes to hello, hallo and hxllo
h*llo subscribes to hllo and heeeello
h[ae]llo subscribes to hello and hallo, but not hillo
- Specified by:
getKeysWithLimitin interfaceRKeys- Parameters:
pattern- - match patternlimit- - limit of keys amount- Returns:
- Iterable object
-
getKeys
public Iterable<String> getKeys()
Description copied from interface:RKeysGet all keys using iterator. Keys traversing with SCAN operation. Each SCAN operation loads up to10keys per request.
-
getKeys
public Iterable<String> getKeys(int count)
Description copied from interface:RKeysGet all keys using iterator. Keys traversing with SCAN operation. Each SCAN operation loads up tocountkeys per request.
-
scanIteratorAsync
public RFuture<ScanResult<Object>> scanIteratorAsync(RedisClient client, MasterSlaveEntry entry, RedisCommand<?> command, long startPos, String pattern, int count)
-
scanIteratorAsync
public RFuture<ScanResult<Object>> scanIteratorAsync(RedisClient client, MasterSlaveEntry entry, long startPos, String pattern, int count)
-
touch
public long touch(String... names)
Description copied from interface:RKeysUpdate the last access time of an object.
-
touchAsync
public RFuture<Long> touchAsync(String... names)
Description copied from interface:RKeysAsyncUpdate the last access time of an object.- Specified by:
touchAsyncin interfaceRKeysAsync- Parameters:
names- of keys- Returns:
- count of objects were touched
-
countExists
public long countExists(String... names)
Description copied from interface:RKeysChecks if provided keys exist- Specified by:
countExistsin interfaceRKeys- Parameters:
names- of keys- Returns:
- amount of existing keys
-
countExistsAsync
public RFuture<Long> countExistsAsync(String... names)
Description copied from interface:RKeysAsyncChecks if provided keys exist- Specified by:
countExistsAsyncin interfaceRKeysAsync- Parameters:
names- of keys- Returns:
- amount of existing keys
-
randomKeyAsync
public RFuture<String> randomKeyAsync()
Description copied from interface:RKeysAsyncGet random key in async mode- Specified by:
randomKeyAsyncin interfaceRKeysAsync- Returns:
- random key
-
deleteByPattern
public long deleteByPattern(String pattern)
Description copied from interface:RKeysDelete multiple objects by a key pattern.Method executes in NON atomic way in cluster mode due to lua script limitations.
Supported glob-style patterns: h?llo subscribes to hello, hallo and hxllo h*llo subscribes to hllo and heeeello h[ae]llo subscribes to hello and hallo, but not hillo
- Specified by:
deleteByPatternin interfaceRKeys- Parameters:
pattern- - match pattern- Returns:
- number of removed keys
-
deleteByPatternAsync
public RFuture<Long> deleteByPatternAsync(String pattern)
Description copied from interface:RKeysAsyncDelete multiple objects by a key pattern.Method executes in NON atomic way in cluster mode due to lua script limitations.
Supported glob-style patterns: h?llo subscribes to hello, hallo and hxllo h*llo subscribes to hllo and heeeello h[ae]llo subscribes to hello and hallo, but not hillo
- Specified by:
deleteByPatternAsyncin interfaceRKeysAsync- Parameters:
pattern- - match pattern- Returns:
- number of removed keys
-
delete
public long delete(String... keys)
Description copied from interface:RKeysDelete multiple objects by name
-
delete
public long delete(RObject... objects)
Description copied from interface:RKeysDelete multiple objects
-
deleteAsync
public RFuture<Long> deleteAsync(RObject... objects)
Description copied from interface:RKeysAsyncDelete multiple objects- Specified by:
deleteAsyncin interfaceRKeysAsync- Parameters:
objects- of Redisson- Returns:
- number of removed keys
-
unlink
public long unlink(String... keys)
Description copied from interface:RKeysDelete multiple objects by name. Actual removal will happen later asynchronously.Requires Redis 4.0+
-
unlinkAsync
public RFuture<Long> unlinkAsync(String... keys)
Description copied from interface:RKeysAsyncDelete multiple objects by name. Actual removal will happen later asynchronously.Requires Redis 4.0+
- Specified by:
unlinkAsyncin interfaceRKeysAsync- Parameters:
keys- - object names- Returns:
- number of removed keys
-
deleteAsync
public RFuture<Long> deleteAsync(String... keys)
Description copied from interface:RKeysAsyncDelete multiple objects by name- Specified by:
deleteAsyncin interfaceRKeysAsync- Parameters:
keys- - object names- Returns:
- number of removed keys
-
count
public long count()
Description copied from interface:RKeysReturns the number of keys in the currently-selected database
-
countAsync
public RFuture<Long> countAsync()
Description copied from interface:RKeysAsyncReturns the number of keys in the currently-selected database in async mode- Specified by:
countAsyncin interfaceRKeysAsync- Returns:
- number of keys
-
flushdbParallel
public void flushdbParallel()
Description copied from interface:RKeysDelete all keys of currently selected database in background without blocking server.Requires Redis 4.0+
- Specified by:
flushdbParallelin interfaceRKeys
-
flushdbParallelAsync
public RFuture<Void> flushdbParallelAsync()
Description copied from interface:RKeysAsyncDelete all keys of currently selected database in background without blocking server.Requires Redis 4.0+
- Specified by:
flushdbParallelAsyncin interfaceRKeysAsync- Returns:
- void
-
flushallParallel
public void flushallParallel()
Description copied from interface:RKeysDelete all keys of all existing databases in background without blocking server.Requires Redis 4.0+
- Specified by:
flushallParallelin interfaceRKeys
-
flushallParallelAsync
public RFuture<Void> flushallParallelAsync()
Description copied from interface:RKeysAsyncDelete all keys of all existing databases in background without blocking server.Requires Redis 4.0+
- Specified by:
flushallParallelAsyncin interfaceRKeysAsync- Returns:
- void
-
flushdb
public void flushdb()
Description copied from interface:RKeysDelete all keys of currently selected database
-
flushdbAsync
public RFuture<Void> flushdbAsync()
Description copied from interface:RKeysAsyncDelete all keys of currently selected database- Specified by:
flushdbAsyncin interfaceRKeysAsync- Returns:
- void
-
flushall
public void flushall()
Description copied from interface:RKeysDelete all keys of all existing databases
-
flushallAsync
public RFuture<Void> flushallAsync()
Description copied from interface:RKeysAsyncDelete all keys of all existing databases- Specified by:
flushallAsyncin interfaceRKeysAsync- Returns:
- void
-
remainTimeToLive
public long remainTimeToLive(String name)
Description copied from interface:RKeysRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLivein interfaceRKeys- Parameters:
name- of key- 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(String name)
Description copied from interface:RKeysAsyncRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsyncin interfaceRKeysAsync- Parameters:
name- of key- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
rename
public void rename(String currentName, String newName)
Description copied from interface:RKeysRename current object key tonewName
-
renameAsync
public RFuture<Void> renameAsync(String currentName, String newName)
Description copied from interface:RKeysAsyncRename current object key tonewName- Specified by:
renameAsyncin interfaceRKeysAsync- Parameters:
currentName- - current name of objectnewName- - new name of object- Returns:
- void
-
renamenx
public boolean renamenx(String oldName, String newName)
Description copied from interface:RKeysRename object witholdNametonewNameonly if new key is not exists
-
renamenxAsync
public RFuture<Boolean> renamenxAsync(String oldName, String newName)
Description copied from interface:RKeysAsyncRename object witholdNametonewNameonly if new key is not exists- Specified by:
renamenxAsyncin interfaceRKeysAsync- Parameters:
oldName- - old name of objectnewName- - new name of object- Returns:
trueif object has been renamed successfully andfalseotherwise
-
clearExpire
public boolean clearExpire(String name)
Description copied from interface:RKeysClear an expire timeout or expire date for object.- Specified by:
clearExpirein interfaceRKeys- Parameters:
name- of object- Returns:
trueif timeout was removedfalseif object does not exist or does not have an associated timeout
-
clearExpireAsync
public RFuture<Boolean> clearExpireAsync(String name)
Description copied from interface:RKeysAsyncClear an expire timeout or expire date for object.- Specified by:
clearExpireAsyncin interfaceRKeysAsync- Parameters:
name- of object- Returns:
trueif timeout was removedfalseif object does not exist or does not have an associated timeout
-
expireAt
public boolean expireAt(String name, long timestamp)
Description copied from interface:RKeysSet an expire date for object. When expire date comes the key will automatically be deleted.
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(String name, long timestamp)
Description copied from interface:RKeysAsyncSet an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAtAsyncin interfaceRKeysAsync- Parameters:
name- of objecttimestamp- - expire date in milliseconds (Unix timestamp)- Returns:
trueif the timeout was set andfalseif not
-
expire
public boolean expire(String name, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RKeysSet a timeout for object. After the timeout has expired, the key will automatically be deleted.
-
expireAsync
public RFuture<Boolean> expireAsync(String name, long timeToLive, TimeUnit timeUnit)
Description copied from interface:RKeysAsyncSet a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expireAsyncin interfaceRKeysAsync- Parameters:
name- of objecttimeToLive- - timeout before object will be deletedtimeUnit- - timeout time unit- Returns:
trueif the timeout was set andfalseif not
-
migrate
public void migrate(String name, String host, int port, int database, long timeout)
Description copied from interface:RKeysTransfer object from source Redis instance to destination Redis instance
-
migrateAsync
public RFuture<Void> migrateAsync(String name, String host, int port, int database, long timeout)
Description copied from interface:RKeysAsyncTransfer object from source Redis instance to destination Redis instance- Specified by:
migrateAsyncin interfaceRKeysAsync- Parameters:
name- of objecthost- - 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 name, String host, int port, int database, long timeout)
Description copied from interface:RKeysCopy object from source Redis instance to destination Redis instance
-
copyAsync
public RFuture<Void> copyAsync(String name, String host, int port, int database, long timeout)
Description copied from interface:RKeysAsyncCopy object from source Redis instance to destination Redis instance in async mode- Specified by:
copyAsyncin interfaceRKeysAsync- Parameters:
name- of objecthost- - 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(String name, int database)
Description copied from interface:RKeysMove object to another database
-
moveAsync
public RFuture<Boolean> moveAsync(String name, int database)
Description copied from interface:RKeysAsyncMove object to another database- Specified by:
moveAsyncin interfaceRKeysAsync- Parameters:
name- of objectdatabase- - Redis database number- Returns:
trueif key was moved elsefalse
-
getKeysStreamByPattern
public Stream<String> getKeysStreamByPattern(String pattern)
Description copied from interface:RKeysGet all keys by pattern using Stream. Keys traversed with SCAN operation. Each SCAN operation loads up to 10 keys per request.Supported glob-style patterns:
h?llo subscribes to hello, hallo and hxllo
h*llo subscribes to hllo and heeeello
h[ae]llo subscribes to hello and hallo, but not hillo
- Specified by:
getKeysStreamByPatternin interfaceRKeys- Parameters:
pattern- - match pattern- Returns:
- Iterable object
-
getKeysStreamByPattern
public Stream<String> getKeysStreamByPattern(String pattern, int count)
Description copied from interface:RKeysGet all keys by pattern using Stream. Keys traversed with SCAN operation. Each SCAN operation loads up tocountkeys per request.Supported glob-style patterns:
h?llo subscribes to hello, hallo and hxllo
h*llo subscribes to hllo and heeeello
h[ae]llo subscribes to hello and hallo, but not hillo
- Specified by:
getKeysStreamByPatternin interfaceRKeys- Parameters:
pattern- - match patterncount- - keys loaded per request to Redis- Returns:
- Iterable object
-
getKeysStream
public Stream<String> getKeysStream()
Description copied from interface:RKeysGet all keys using Stream. Keys traversing with SCAN operation. Each SCAN operation loads up to10keys per request.- Specified by:
getKeysStreamin interfaceRKeys- Returns:
- Iterable object
-
getKeysStream
public Stream<String> getKeysStream(int count)
Description copied from interface:RKeysGet all keys using Stream. Keys traversing with SCAN operation. Each SCAN operation loads up tocountkeys per request.- Specified by:
getKeysStreamin interfaceRKeys- Parameters:
count- - keys loaded per request to Redis- Returns:
- Iterable object
-
swapdb
public void swapdb(int db1, int db2)Description copied from interface:RKeysSwap two databases.
-
swapdbAsync
public RFuture<Void> swapdbAsync(int db1, int db2)
Description copied from interface:RKeysAsyncSwap two databases.Requires Redis 4.0+
- Specified by:
swapdbAsyncin interfaceRKeysAsync- Returns:
- void
-
-