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 Type
    Method
    Description
    copy(byte[] sourceKey, byte[] targetKey, boolean replace)
    Copy given sourceKey to targetKey.
    del(byte[]... keys)
    Delete given keys.
    byte[]
    dump(byte[] key)
    Retrieve serialized version of the value stored at key.
    encodingOf(byte[] key)
    Get the type of internal representation used for storing the value at the given key.
    default Boolean
    exists(byte[] key)
    Determine if given key exists.
    exists(byte[]... keys)
    Count how many of the given keys exist.
    expire(byte[] key, long seconds)
    Set time to live for given key in seconds.
    expireAt(byte[] key, long unixTime)
    Set the expiration for given key as a UNIX timestamp.
    idletime(byte[] key)
    Get the Duration since the object stored at the given key is idle.
    Set<byte[]>
    keys(byte[] pattern)
    Find all keys matching the given pattern.
    move(byte[] key, int dbIndex)
    Move given key to database with index.
    persist(byte[] key)
    Remove the expiration from given key.
    pExpire(byte[] key, long millis)
    Set time to live for given key in milliseconds.
    pExpireAt(byte[] key, long unixTimeInMillis)
    Set the expiration for given key as a UNIX timestamp in milliseconds.
    pTtl(byte[] key)
    Get the precise time to live for key in milliseconds.
    pTtl(byte[] key, TimeUnit timeUnit)
    Get the precise time to live for key in and convert it to the given TimeUnit.
    byte[]
    Return a random key from the keyspace.
    refcount(byte[] key)
    Get the number of references of the value associated with the specified key.
    void
    rename(byte[] oldKey, byte[] newKey)
    Rename key oldKey to newKey.
    renameNX(byte[] oldKey, byte[] newKey)
    Rename key oldKey to newKey only if newKey does not exist.
    default void
    restore(byte[] key, long ttlInMillis, byte[] serializedValue)
    Create key using the serializedValue, previously obtained using dump(byte[]).
    void
    restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolean replace)
    Create key using the serializedValue, previously obtained using dump(byte[]).
    default Cursor<byte[]>
    Use a Cursor to iterate over keys.
    Cursor<byte[]>
    scan(ScanOptions options)
    Use a Cursor to iterate over keys.
    List<byte[]>
    sort(byte[] key, SortParameters params)
    Sort the elements for key.
    sort(byte[] key, SortParameters params, byte[] storeKey)
    Sort the elements for key and store result in storeKey.
    touch(byte[]... keys)
    Alter the last access time of given key(s).
    ttl(byte[] key)
    Get the time to live for key in seconds.
    ttl(byte[] key, TimeUnit timeUnit)
    Get the time to live for key in and convert it to the given TimeUnit.
    type(byte[] key)
    Determine the type stored at key.
    unlink(byte[]... keys)
    Unlink the keys from the keyspace.
  • Method Details

    • copy

      @Nullable Boolean copy(byte[] sourceKey, byte[] targetKey, boolean replace)
      Copy given sourceKey to targetKey.
      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

      @Nullable default Boolean exists(byte[] key)
      Determine if given key exists.
      Parameters:
      key - must not be null.
      Returns:
      true if key exists. null when used in pipeline / transaction.
      See Also:
    • exists

      @Nullable Long exists(byte[]... keys)
      Count how many of the given keys exist. Providing the very same key 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

      @Nullable Long del(byte[]... keys)
      Delete given keys.
      Parameters:
      keys - must not be null.
      Returns:
      The number of keys that were removed. null when used in pipeline / transaction.
      See Also:
    • unlink

      @Nullable Long unlink(byte[]... keys)
      Unlink the keys from the keyspace. Unlike with del(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

      @Nullable DataType type(byte[] key)
      Determine the type stored at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • touch

      @Nullable Long touch(byte[]... keys)
      Alter the last access time of given key(s).
      Parameters:
      keys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.1
      See Also:
    • keys

      @Nullable Set<byte[]> keys(byte[] pattern)
      Find all keys matching the given pattern.
      Parameters:
      pattern - must not be null.
      Returns:
      empty Set if no match found. null when used in pipeline / transaction.
      See Also:
    • scan

      default Cursor<byte[]> scan(KeyScanOptions options)
      Use a Cursor to iterate over keys.
      Parameters:
      options - must not be null.
      Returns:
      never null.
      Since:
      2.4
      See Also:
    • scan

      Cursor<byte[]> scan(ScanOptions options)
      Use a Cursor to iterate over keys.
      Parameters:
      options - must not be null.
      Returns:
      never null.
      Since:
      1.4
      See Also:
    • randomKey

      @Nullable 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[] oldKey, byte[] newKey)
      Rename key oldKey to newKey.
      Parameters:
      oldKey - must not be null.
      newKey - must not be null.
      See Also:
    • renameNX

      @Nullable Boolean renameNX(byte[] oldKey, byte[] newKey)
      Rename key oldKey to newKey only if newKey does not exist.
      Parameters:
      oldKey - must not be null.
      newKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • expire

      @Nullable Boolean expire(byte[] key, long seconds)
      Set time to live for given key in seconds.
      Parameters:
      key - must not be null.
      seconds -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • pExpire

      @Nullable Boolean pExpire(byte[] key, long millis)
      Set time to live for given key in milliseconds.
      Parameters:
      key - must not be null.
      millis -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • expireAt

      @Nullable Boolean expireAt(byte[] key, long unixTime)
      Set the expiration for given key as a UNIX timestamp.
      Parameters:
      key - must not be null.
      unixTime -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • pExpireAt

      @Nullable Boolean pExpireAt(byte[] key, long unixTimeInMillis)
      Set the expiration for given key as a UNIX timestamp in milliseconds.
      Parameters:
      key - must not be null.
      unixTimeInMillis -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • persist

      @Nullable Boolean persist(byte[] key)
      Remove the expiration from given key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • move

      @Nullable Boolean move(byte[] key, int dbIndex)
      Move given key to database with index.
      Parameters:
      key - must not be null.
      dbIndex -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • ttl

      @Nullable Long ttl(byte[] key)
      Get the time to live for key in seconds.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • ttl

      @Nullable Long ttl(byte[] key, TimeUnit timeUnit)
      Get the time to live for key in and convert it to the given TimeUnit.
      Parameters:
      key - must not be null.
      timeUnit - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      1.8
      See Also:
    • pTtl

      @Nullable Long pTtl(byte[] key)
      Get the precise time to live for key in milliseconds.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • pTtl

      @Nullable Long pTtl(byte[] key, TimeUnit timeUnit)
      Get the precise time to live for key in and convert it to the given TimeUnit.
      Parameters:
      key - must not be null.
      timeUnit - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      1.8
      See Also:
    • sort

      @Nullable List<byte[]> sort(byte[] key, SortParameters params)
      Sort the elements for key.
      Parameters:
      key - must not be null.
      params - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • sort

      @Nullable Long sort(byte[] key, SortParameters params, byte[] storeKey)
      Sort the elements for key and store result in storeKey.
      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

      @Nullable byte[] dump(byte[] key)
      Retrieve serialized version of the value stored at key.
      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)
      Create key using the serializedValue, previously obtained using dump(byte[]).
      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)
      Create key using the serializedValue, previously obtained using dump(byte[]).
      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

      @Nullable ValueEncoding encodingOf(byte[] key)
      Get the type of internal representation used for storing the value at the given key.
      Parameters:
      key - must not be null.
      Returns:
      ValueEncoding.RedisValueEncoding.VACANT if key does not exist or null when used in pipeline / transaction.
      Throws:
      IllegalArgumentException - if key is null.
      Since:
      2.1
      See Also:
    • idletime

      @Nullable Duration idletime(byte[] key)
      Get the Duration since the object stored at the given key is idle.
      Parameters:
      key - must not be null.
      Returns:
      null if key does not exist or when used in pipeline / transaction.
      Throws:
      IllegalArgumentException - if key is null.
      Since:
      2.1
      See Also:
    • refcount

      @Nullable Long refcount(byte[] key)
      Get the number of references of the value associated with the specified key.
      Parameters:
      key - must not be null.
      Returns:
      null if key does not exist or when used in pipeline / transaction.
      Throws:
      IllegalArgumentException - if key is null.
      Since:
      2.1
      See Also: