Interface RedisKeyCommands
- All Known Subinterfaces:
DefaultedRedisClusterConnection, DefaultedRedisConnection, RedisClusterConnection, RedisCommands, RedisConnection, RedisConnectionUtils.RedisConnectionProxy, StringRedisConnection
- All Known Implementing Classes:
AbstractRedisConnection, DefaultStringRedisConnection, JedisClusterConnection, JedisConnection, LettuceClusterConnection, LettuceConnection
Key-specific commands supported by Redis.
- Author:
- Costin Leau, Christoph Strobl, Mark Paluch, ihaohong, Yordan Tsintsov
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault BooleanapplyExpiration(byte @NonNull [] key, @NonNull Expiration expiration, @NonNull ExpirationOptions options) Copy givensourceKeytotargetKey.Delete givenkeys.delex(byte @NonNull [] key, @NonNull CompareCondition condition) Delete a key based on the providedCompareCondition.Get the hash digest for the value stored in the specified key as a hexadecimal string.byte[]Retrieve serialized version of the value stored atkey.encodingOf(byte @NonNull [] key) Get the type of internal representation used for storing the value at the givenkey.default BooleanDetermine if givenkeyexists.Count how many of the givenkeysexist.default BooleanSet time to live for givenkeyin seconds.expire(byte @NonNull [] key, long seconds, @NonNull ExpirationOptions.Condition condition) Set time to live for givenkeyin seconds.default BooleanSet time to live for givenkeyusingsecondsprecision.default BooleanSet the expiration for givenkeyas a UNIX timestamp.expireAt(byte @NonNull [] key, long unixTime, @NonNull ExpirationOptions.Condition condition) Set the expiration for givenkeyas a UNIX timestamp.default BooleanSet the expiration for givenkeyas a UNIX timestamp insecondsprecision.Get theDurationsince the object stored at the givenkeyis idle.Retrieve all keys matching the given pattern.Move givenkeyto database withdbIndex.Remove the expiration from givenkey.default BooleanSet time to live for givenkeyin milliseconds.pExpire(byte @NonNull [] key, long millis, @NonNull ExpirationOptions.Condition condition) Set time to live for givenkeyin milliseconds.default BooleanSet time to live for givenkeyusingmillisecondsprecision.default BooleanSet the expiration for givenkeyas a UNIX timestamp in milliseconds.pExpireAt(byte @NonNull [] key, long unixTimeInMillis, @NonNull ExpirationOptions.Condition condition) Set the expiration for givenkeyas a UNIX timestamp in milliseconds.default BooleanSet the expiration for givenkeyas a UNIX timestamp inmillisecondsprecision.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.Get the number of references of the value associated with the specifiedkey.voidRename keyoldKeytonewKey.Rename keyoldKeytonewKeyonly ifnewKeydoes not exist.default voidvoidscan(@NonNull KeyScanOptions options) Use aCursorto iterate over keys.scan(@Nullable ScanOptions options) Use aCursorto iterate over keys.sort(byte @NonNull [] key, @Nullable SortParameters params) Sort the elements forkey.sort(byte @NonNull [] key, @Nullable SortParameters params, byte @NonNull [] storeKey) Sort the elements forkeyand store result instoreKey.Alter the last access time of givenkey(s).Get the time to live forkeyin seconds.Get the time to live forkeyin and convert it to the givenTimeUnit.Determine the type stored atkey.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:
-
digest
-
exists
-
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
-
delex
Delete a key based on the providedCompareCondition.- Parameters:
key- must not be null.condition- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 4.1
- 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
-
touch
-
keys
Retrieve all keys matching the given pattern.IMPORTANT: The KEYS command is non-interruptible and scans the entire keyspace which may cause performance issues. Consider
scan(ScanOptions)for large datasets.- 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- can be null.- Returns:
- never null.
- Since:
- 1.4
- See Also:
-
randomKey
byte[] randomKey()Return a random key from the keyspace.- Returns:
- null if no keys available or when used in pipeline or transaction.
- See Also:
-
rename
-
renameNX
-
applyExpiration
default Boolean applyExpiration(byte @NonNull [] key, @NonNull Expiration expiration, @NonNull ExpirationOptions options) - Parameters:
key- must not be null.expiration- theExpirationto apply.options- additional options to be sent along with the command.- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- See Also:
-
expire
Set time to live for givenkeyin seconds.- Parameters:
key- must not be null.seconds-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- See Also:
-
expire
Set time to live for givenkeyin seconds.- Parameters:
key- must not be null.seconds-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- See Also:
-
expire
Set time to live for givenkeyusingsecondsprecision.- Parameters:
key- must not be null.duration-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- See Also:
-
pExpire
Set time to live for givenkeyin milliseconds.- Parameters:
key- must not be null.millis-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- See Also:
-
pExpire
Set time to live for givenkeyin milliseconds.- Parameters:
key- must not be null.millis-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- See Also:
-
pExpire
Set time to live for givenkeyusingmillisecondsprecision.- Parameters:
key- must not be null.duration-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- 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. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- See Also:
-
expireAt
Boolean expireAt(byte @NonNull [] key, long unixTime, @NonNull ExpirationOptions.Condition condition) Set the expiration for givenkeyas a UNIX timestamp.- Parameters:
key- must not be null.unixTime-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- See Also:
-
expireAt
Set the expiration for givenkeyas a UNIX timestamp insecondsprecision.- Parameters:
key- must not be null.unixTime-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- 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. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- See Also:
-
pExpireAt
Boolean pExpireAt(byte @NonNull [] key, long unixTimeInMillis, @NonNull ExpirationOptions.Condition condition) Set the expiration for givenkeyas a UNIX timestamp in milliseconds.- Parameters:
key- must not be null.unixTimeInMillis-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- See Also:
-
pExpireAt
Set the expiration for givenkeyas a UNIX timestamp inmillisecondsprecision.- Parameters:
key- must not be null.unixTime-- Returns:
- null when used in pipeline / transaction. true if the timeout was set or false if the timeout was not set; for example, the key doesn't exist, or the operation was skipped because of the provided arguments.
- Since:
- 3.5
- See Also:
-
persist
-
move
-
ttl
-
ttl
-
pTtl
-
pTtl
-
sort
Sort the elements forkey.- Parameters:
key- must not be null.params- can 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- can 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
- Parameters:
key- must not be null.ttlInMillis-serializedValue- must not be null.- See Also:
-
restore
-
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:
-