Interface RedisKeyCommands
- All Known Subinterfaces:
DefaultedRedisClusterConnection
,DefaultedRedisConnection
,RedisClusterConnection
,RedisCommands
,RedisConnection
,RedisConnectionUtils.RedisConnectionProxy
,StringRedisConnection
- All Known Implementing Classes:
AbstractRedisConnection
,DefaultStringRedisConnection
,JedisClusterConnection
,JedisConnection
,LettuceClusterConnection
,LettuceConnection
@NullUnmarked
public interface RedisKeyCommands
Key-specific commands supported by Redis.
- Author:
- Costin Leau, Christoph Strobl, Mark Paluch, ihaohong
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault Boolean
applyExpiration
(byte @NonNull [] key, @NonNull Expiration expiration, @NonNull ExpirationOptions options) copy
(byte @NonNull [] sourceKey, byte @NonNull [] targetKey, boolean replace) Copy givensourceKey
totargetKey
.del
(byte @NonNull [] @NonNull ... keys) Delete givenkeys
.byte[]
dump
(byte @NonNull [] key) 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 Boolean
exists
(byte @NonNull [] key) Determine if givenkey
exists.exists
(byte @NonNull [] @NonNull ... keys) Count how many of the givenkeys
exist.default Boolean
expire
(byte @NonNull [] key, long seconds) Set time to live for givenkey
in seconds.expire
(byte @NonNull [] key, long seconds, @NonNull ExpirationOptions.Condition condition) Set time to live for givenkey
in seconds.default Boolean
Set time to live for givenkey
usingseconds
precision.default Boolean
expireAt
(byte @NonNull [] key, long unixTime) Set the expiration for givenkey
as a UNIX timestamp.expireAt
(byte @NonNull [] key, long unixTime, @NonNull ExpirationOptions.Condition condition) Set the expiration for givenkey
as a UNIX timestamp.default Boolean
Set the expiration for givenkey
as a UNIX timestamp inseconds
precision.idletime
(byte @NonNull [] key) Get theDuration
since the object stored at the givenkey
is idle.Set<byte @NonNull []>
keys
(byte @NonNull [] pattern) Retrieve all keys matching the given pattern.move
(byte @NonNull [] key, int dbIndex) Move givenkey
to database withindex
.persist
(byte @NonNull [] key) Remove the expiration from givenkey
.default Boolean
pExpire
(byte @NonNull [] key, long millis) Set time to live for givenkey
in milliseconds.pExpire
(byte @NonNull [] key, long millis, @NonNull ExpirationOptions.Condition condition) Set time to live for givenkey
in milliseconds.default Boolean
Set time to live for givenkey
usingmilliseconds
precision.default Boolean
pExpireAt
(byte @NonNull [] key, long unixTimeInMillis) Set the expiration for givenkey
as a UNIX timestamp in milliseconds.pExpireAt
(byte @NonNull [] key, long unixTimeInMillis, @NonNull ExpirationOptions.Condition condition) Set the expiration for givenkey
as a UNIX timestamp in milliseconds.default Boolean
Set the expiration for givenkey
as a UNIX timestamp inmilliseconds
precision.pTtl
(byte @NonNull [] key) Get the precise time to live forkey
in milliseconds.Get the precise time to live forkey
in and convert it to the givenTimeUnit
.byte[]
Return a random key from the keyspace.refcount
(byte @NonNull [] key) Get the number of references of the value associated with the specifiedkey
.void
rename
(byte @NonNull [] oldKey, byte @NonNull [] newKey) Rename keyoldKey
tonewKey
.renameNX
(byte @NonNull [] oldKey, byte @NonNull [] newKey) Rename keyoldKey
tonewKey
only ifnewKey
does not exist.default void
restore
(byte @NonNull [] key, long ttlInMillis, byte @NonNull [] serializedValue) void
restore
(byte @NonNull [] key, long ttlInMillis, byte @NonNull [] serializedValue, boolean replace) default Cursor<byte @NonNull []>
scan
(@NonNull KeyScanOptions options) Use aCursor
to iterate over keys.Cursor<byte @NonNull []>
scan
(@Nullable ScanOptions options) Use aCursor
to iterate over keys.List<byte @NonNull []>
sort
(byte @NonNull [] key, @Nullable SortParameters params) Sort the elements forkey
.sort
(byte @NonNull [] key, @Nullable SortParameters params, byte @NonNull [] storeKey) Sort the elements forkey
and store result instoreKey
.touch
(byte @NonNull [] @NonNull ... keys) Alter the last access time of givenkey(s)
.ttl
(byte @NonNull [] key) Get the time to live forkey
in seconds.Get the time to live forkey
in and convert it to the givenTimeUnit
.type
(byte @NonNull [] key) Determine the type stored atkey
.unlink
(byte @NonNull [] @NonNull ... keys) Unlink thekeys
from the keyspace.
-
Method Details
-
copy
Copy givensourceKey
totargetKey
.- 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 givenkey
exists.- 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 givenkeys
exist. Providing the very samekey
more 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 thekeys
from 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
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
Set
if no match found. null when used in pipeline / transaction. - See Also:
-
scan
Use aCursor
to iterate over keys.- Parameters:
options
- must not be null.- Returns:
- never null.
- Since:
- 2.4
- See Also:
-
scan
Use aCursor
to 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
void rename(byte @NonNull [] oldKey, byte @NonNull [] newKey) Rename keyoldKey
tonewKey
.- Parameters:
oldKey
- must not be null.newKey
- must not be null.- See Also:
-
renameNX
Rename keyoldKey
tonewKey
only ifnewKey
does not exist.- Parameters:
oldKey
- must not be null.newKey
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
applyExpiration
default Boolean applyExpiration(byte @NonNull [] key, @NonNull Expiration expiration, @NonNull ExpirationOptions options) - Parameters:
key
- must not be null.expiration
- theExpiration
to 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 givenkey
in 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 givenkey
in 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 givenkey
usingseconds
precision.- 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 givenkey
in 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 givenkey
in 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 givenkey
usingmilliseconds
precision.- 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 givenkey
as 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 givenkey
as 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 givenkey
as a UNIX timestamp inseconds
precision.- 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 givenkey
as 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 givenkey
as 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 givenkey
as a UNIX timestamp inmilliseconds
precision.- 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
Remove the expiration from givenkey
.- Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
move
Move givenkey
to database withindex
.- Parameters:
key
- must not be null.dbIndex
-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
ttl
Get the time to live forkey
in seconds.- Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
ttl
Get the time to live forkey
in 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 forkey
in milliseconds.- Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
pTtl
Get the precise time to live forkey
in 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
- can be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
sort
Sort the elements forkey
and 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
byte[] dump(byte @NonNull [] key) 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 @NonNull [] key, long ttlInMillis, byte @NonNull [] serializedValue) - Parameters:
key
- must not be null.ttlInMillis
-serializedValue
- must not be null.- See Also:
-
restore
void restore(byte @NonNull [] key, long ttlInMillis, byte @NonNull [] 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.VACANT
if key does not exist or null when used in pipeline / transaction.- Throws:
IllegalArgumentException
- ifkey
is null.- Since:
- 2.1
- See Also:
-
idletime
Get theDuration
since the object stored at the givenkey
is idle.- Parameters:
key
- must not be null.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- Throws:
IllegalArgumentException
- ifkey
is 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
- ifkey
is null.- Since:
- 2.1
- See Also:
-