Interface RedisKeyCommands
- All Known Subinterfaces:
DefaultedRedisClusterConnection,DefaultedRedisConnection,RedisClusterConnection,RedisCommands,RedisConnection,RedisConnectionUtils.RedisConnectionProxy,StringRedisConnection
- All Known Implementing Classes:
AbstractRedisConnection,DefaultStringRedisConnection,JedisClusterConnection,JedisConnection,LettuceClusterConnection,LettuceConnection
public interface RedisKeyCommands
Key-specific commands supported by Redis.
- Author:
- Costin Leau, Christoph Strobl, Mark Paluch, ihaohong
-
Method Summary
Modifier and TypeMethodDescriptioncopy(byte[] sourceKey, byte[] targetKey, boolean replace) Copy givensourceKeytotargetKey.del(byte[]... keys) Delete givenkeys.byte[]dump(byte[] key) Retrieve serialized version of the value stored atkey.encodingOf(byte[] key) Get the type of internal representation used for storing the value at the givenkey.default Booleanexists(byte[] key) Determine if givenkeyexists.exists(byte[]... keys) Count how many of the givenkeysexist.expire(byte[] key, long seconds) Set time to live for givenkeyin seconds.expireAt(byte[] key, long unixTime) Set the expiration for givenkeyas a UNIX timestamp.idletime(byte[] key) Get theDurationsince the object stored at the givenkeyis idle.Set<byte[]>keys(byte[] pattern) Find all keys matching the givenpattern.move(byte[] key, int dbIndex) Move givenkeyto database withindex.persist(byte[] key) Remove the expiration from givenkey.pExpire(byte[] key, long millis) Set time to live for givenkeyin milliseconds.pExpireAt(byte[] key, long unixTimeInMillis) Set the expiration for givenkeyas a UNIX timestamp in milliseconds.pTtl(byte[] key) Get the precise time to live forkeyin milliseconds.Get the precise time to live forkeyin and convert it to the givenTimeUnit.byte[]Return a random key from the keyspace.refcount(byte[] key) Get the number of references of the value associated with the specifiedkey.voidrename(byte[] oldKey, byte[] newKey) Rename keyoldKeytonewKey.renameNX(byte[] oldKey, byte[] newKey) Rename keyoldKeytonewKeyonly ifnewKeydoes not exist.default voidrestore(byte[] key, long ttlInMillis, byte[] serializedValue) voidrestore(byte[] key, long ttlInMillis, byte[] serializedValue, boolean replace) default Cursor<byte[]>scan(KeyScanOptions options) Use aCursorto iterate over keys.Cursor<byte[]>scan(ScanOptions options) Use aCursorto iterate over keys.List<byte[]>sort(byte[] key, SortParameters params) Sort the elements forkey.sort(byte[] key, SortParameters params, byte[] storeKey) Sort the elements forkeyand store result instoreKey.touch(byte[]... keys) Alter the last access time of givenkey(s).ttl(byte[] key) Get the time to live forkeyin seconds.Get the time to live forkeyin and convert it to the givenTimeUnit.type(byte[] key) Determine the type stored atkey.unlink(byte[]... keys) Unlink thekeysfrom the keyspace.
-
Method Details
-
copy
Copy givensourceKeytotargetKey.- Parameters:
sourceKey- must not be null.targetKey- must not be null.replace- whether to replace existing keys.- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
exists
Determine if givenkeyexists.- Parameters:
key- must not be null.- Returns:
- true if key exists. null when used in pipeline / transaction.
- See Also:
-
exists
Count how many of the givenkeysexist. Providing the very samekeymore than once also counts multiple times.- Parameters:
keys- must not be null.- Returns:
- the number of keys existing among the ones specified as arguments. null when used in pipeline / transaction.
- Since:
- 2.1
-
del
Delete givenkeys.- Parameters:
keys- must not be null.- Returns:
- The number of keys that were removed. null when used in pipeline / transaction.
- See Also:
-
unlink
Unlink thekeysfrom the keyspace. Unlike withdel(byte[]...)the actual memory reclaiming here happens asynchronously.- Parameters:
keys- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.1
- See Also:
-
type
Determine the type stored atkey.- Parameters:
key- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
touch
Alter the last access time of givenkey(s).- Parameters:
keys- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.1
- See Also:
-
keys
Find all keys matching the givenpattern.- Parameters:
pattern- must not be null.- Returns:
- empty
Setif no match found. null when used in pipeline / transaction. - See Also:
-
scan
Use aCursorto iterate over keys.- Parameters:
options- must not be null.- Returns:
- never null.
- Since:
- 2.4
- See Also:
-
scan
Use aCursorto iterate over keys.- Parameters:
options- must not be null.- Returns:
- never null.
- Since:
- 1.4
- See Also:
-
randomKey
Return a random key from the keyspace.- Returns:
- null if no keys available or when used in pipeline or transaction.
- See Also:
-
rename
void rename(byte[] oldKey, byte[] newKey) Rename keyoldKeytonewKey.- Parameters:
oldKey- must not be null.newKey- must not be null.- See Also:
-
renameNX
Rename keyoldKeytonewKeyonly ifnewKeydoes not exist.- Parameters:
oldKey- must not be null.newKey- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
expire
Set time to live for givenkeyin seconds.- Parameters:
key- must not be null.seconds-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
pExpire
Set time to live for givenkeyin milliseconds.- Parameters:
key- must not be null.millis-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
expireAt
Set the expiration for givenkeyas a UNIX timestamp.- Parameters:
key- must not be null.unixTime-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
pExpireAt
Set the expiration for givenkeyas a UNIX timestamp in milliseconds.- Parameters:
key- must not be null.unixTimeInMillis-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
persist
Remove the expiration from givenkey.- Parameters:
key- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
move
Move givenkeyto database withindex.- Parameters:
key- must not be null.dbIndex-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
ttl
Get the time to live forkeyin seconds.- Parameters:
key- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
ttl
Get the time to live forkeyin and convert it to the givenTimeUnit.- Parameters:
key- must not be null.timeUnit- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 1.8
- See Also:
-
pTtl
Get the precise time to live forkeyin milliseconds.- Parameters:
key- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
pTtl
Get the precise time to live forkeyin and convert it to the givenTimeUnit.- Parameters:
key- must not be null.timeUnit- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 1.8
- See Also:
-
sort
Sort the elements forkey.- Parameters:
key- must not be null.params- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
sort
Sort the elements forkeyand store result instoreKey.- Parameters:
key- must not be null.params- must not be null.storeKey- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
dump
Retrieve serialized version of the value stored atkey.- Parameters:
key- must not be null.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- See Also:
-
restore
default void restore(byte[] key, long ttlInMillis, byte[] serializedValue) - Parameters:
key- must not be null.ttlInMillis-serializedValue- must not be null.- See Also:
-
restore
void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolean replace) - Parameters:
key- must not be null.ttlInMillis-serializedValue- must not be null.replace- use true to replace a potentially existing value instead of erroring.- Since:
- 2.1
- See Also:
-
encodingOf
Get the type of internal representation used for storing the value at the givenkey.- Parameters:
key- must not be null.- Returns:
ValueEncoding.RedisValueEncoding.VACANTif key does not exist or null when used in pipeline / transaction.- Throws:
IllegalArgumentException- ifkeyis null.- Since:
- 2.1
- See Also:
-
idletime
Get theDurationsince the object stored at the givenkeyis idle.- Parameters:
key- must not be null.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- Throws:
IllegalArgumentException- ifkeyis null.- Since:
- 2.1
- See Also:
-
refcount
Get the number of references of the value associated with the specifiedkey.- Parameters:
key- must not be null.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- Throws:
IllegalArgumentException- ifkeyis null.- Since:
- 2.1
- See Also:
-