Interface RedisHashCommands

All Known Subinterfaces:
DefaultedRedisClusterConnection, DefaultedRedisConnection, RedisClusterConnection, RedisCommands, RedisConnection, RedisConnectionUtils.RedisConnectionProxy, StringRedisConnection
All Known Implementing Classes:
AbstractRedisConnection, DefaultStringRedisConnection, JedisClusterConnection, JedisConnection, LettuceClusterConnection, LettuceConnection

@NullUnmarked public interface RedisHashCommands
Hash-specific commands supported by Redis.
Author:
Costin Leau, Christoph Strobl, Mark Paluch, Tihomir Mateev
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default List<@NonNull Long>
    applyHashFieldExpiration(byte @NonNull [] key, @NonNull Expiration expiration, byte @NonNull [] @NonNull ... fields)
    Apply a given Expiration to the given fields.
    default List<@NonNull Long>
    applyHashFieldExpiration(byte @NonNull [] key, @NonNull Expiration expiration, @NonNull ExpirationOptions options, byte @NonNull [] @NonNull ... fields)
     
    hDel(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
    Delete given hash fields.
    hExists(byte @NonNull [] key, byte @NonNull [] field)
    Determine if given hash field exists.
    default List<@NonNull Long>
    hExpire(byte @NonNull [] key, long seconds, byte @NonNull [] @NonNull ... fields)
    Set time to live for given fields in seconds.
    List<@NonNull Long>
    hExpire(byte @NonNull [] key, long seconds, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
    Set time to live for given fields in seconds.
    default List<@NonNull Long>
    hExpire(byte @NonNull [] key, @NonNull Duration ttl, byte @NonNull [] @NonNull ... fields)
    Set time to live for given fields.
    default List<Long>
    hExpireAt(byte @NonNull [] key, long unixTime, byte @NonNull [] @NonNull ... fields)
    Set the expiration for given field as a UNIX timestamp.
    List<@NonNull Long>
    hExpireAt(byte @NonNull [] key, long unixTime, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
    Set the expiration for given field as a UNIX timestamp.
    byte[]
    hGet(byte @NonNull [] key, byte @NonNull [] field)
    Get value for given field from hash at key.
    Map<byte @NonNull [], byte @NonNull []>
    hGetAll(byte @NonNull [] key)
    Get entire hash stored at key.
    hIncrBy(byte @NonNull [] key, byte @NonNull [] field, double delta)
    Increment value of a hash field by the given delta.
    hIncrBy(byte @NonNull [] key, byte @NonNull [] field, long delta)
    Increment value of a hash field by the given delta.
    Set<byte @NonNull []>
    hKeys(byte @NonNull [] key)
    Get key set (fields) of hash at key.
    hLen(byte @NonNull [] key)
    Get size of hash at key.
    List<byte[]>
    hMGet(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
    Get values for given fields from hash at key.
    void
    hMSet(byte @NonNull [] key, Map<byte[],byte[]> hashes)
    Set multiple hash fields to multiple values using data provided in hashes
    List<@NonNull Long>
    hPersist(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
    Remove the expiration from given field.
    default List<@NonNull Long>
    hpExpire(byte @NonNull [] key, long millis, byte @NonNull [] @NonNull ... fields)
    Set time to live for given fields in milliseconds.
    List<@NonNull Long>
    hpExpire(byte @NonNull [] key, long millis, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
    Set time to live for given fields in milliseconds.
    default List<@NonNull Long>
    hpExpire(byte @NonNull [] key, @NonNull Duration ttl, byte @NonNull [] @NonNull ... fields)
    Set time to live for given fields in milliseconds.
    default List<@NonNull Long>
    hpExpireAt(byte @NonNull [] key, long unixTimeInMillis, byte @NonNull [] @NonNull ... fields)
    Set the expiration for given field as a UNIX timestamp in milliseconds.
    List<@NonNull Long>
    hpExpireAt(byte @NonNull [] key, long unixTimeInMillis, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
    Set the expiration for given field as a UNIX timestamp in milliseconds.
    List<@NonNull Long>
    hpTtl(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
    Get the time to live for fields in milliseconds.
    byte[]
    hRandField(byte @NonNull [] key)
    Return a random field from the hash stored at key.
    List<byte @NonNull []>
    hRandField(byte @NonNull [] key, long count)
    Return a random field from the hash stored at key.
    Map.Entry<byte @NonNull [], byte @NonNull []>
    hRandFieldWithValues(byte @NonNull [] key)
    Return a random field from the hash along with its value stored at key.
    List<@NonNull Map.Entry<byte @NonNull [], byte @NonNull []>>
    hRandFieldWithValues(byte @NonNull [] key, long count)
    Return a random field from the hash along with its value stored at key.
    Cursor<@NonNull Map.Entry<byte @NonNull [], byte @NonNull []>>
    hScan(byte @NonNull [] key, ScanOptions options)
    Use a Cursor to iterate over entries in hash at key.
    hSet(byte @NonNull [] key, byte @NonNull [] field, byte @NonNull [] value)
    Set the value of a hash field.
    hSetNX(byte @NonNull [] key, byte @NonNull [] field, byte @NonNull [] value)
    Set the value of a hash field only if field does not exist.
    hStrLen(byte @NonNull [] key, byte @NonNull [] field)
    Returns the length of the value associated with field in the hash stored at key.
    List<@NonNull Long>
    hTtl(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
    Get the time to live for fields in seconds.
    List<@NonNull Long>
    hTtl(byte @NonNull [] key, @NonNull TimeUnit timeUnit, byte @NonNull [] @NonNull ... fields)
    Get the time to live for fields in and convert it to the given TimeUnit.
    List<byte @NonNull []>
    hVals(byte @NonNull [] key)
    Get entry set (values) of hash at field.
  • Method Details

    • hSet

      Boolean hSet(byte @NonNull [] key, byte @NonNull [] field, byte @NonNull [] value)
      Set the value of a hash field.
      Parameters:
      key - must not be null.
      field - must not be null.
      value - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hSetNX

      Boolean hSetNX(byte @NonNull [] key, byte @NonNull [] field, byte @NonNull [] value)
      Set the value of a hash field only if field does not exist.
      Parameters:
      key - must not be null.
      field - must not be null.
      value - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hGet

      byte[] hGet(byte @NonNull [] key, byte @NonNull [] field)
      Get value for given field from hash at key.
      Parameters:
      key - must not be null.
      field - must not be null.
      Returns:
      null when key or field do not exists or when used in pipeline / transaction.
      See Also:
    • hMGet

      List<byte[]> hMGet(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
      Get values for given fields from hash at key. Values are in the order of the requested keys Absent field values are represented using null in the resulting List.
      Parameters:
      key - must not be null.
      fields - must not be empty.
      Returns:
      empty List if key does not exist. null when used in pipeline / transaction.
      See Also:
    • hMSet

      void hMSet(byte @NonNull [] key, Map<byte[],byte[]> hashes)
      Set multiple hash fields to multiple values using data provided in hashes
      Parameters:
      key - must not be null.
      hashes - must not be null.
      See Also:
    • hIncrBy

      Long hIncrBy(byte @NonNull [] key, byte @NonNull [] field, long delta)
      Increment value of a hash field by the given delta.
      Parameters:
      key - must not be null.
      field - must not be null.
      delta -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hIncrBy

      Double hIncrBy(byte @NonNull [] key, byte @NonNull [] field, double delta)
      Increment value of a hash field by the given delta.
      Parameters:
      key - must not be null.
      field - must not be null.
      delta -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hExists

      Boolean hExists(byte @NonNull [] key, byte @NonNull [] field)
      Determine if given hash field exists.
      Parameters:
      key - must not be null.
      field - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hDel

      Long hDel(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
      Delete given hash fields.
      Parameters:
      key - must not be null.
      fields - must not be empty.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hLen

      Long hLen(byte @NonNull [] key)
      Get size of hash at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hKeys

      Set<byte @NonNull []> hKeys(byte @NonNull [] key)
      Get key set (fields) of hash at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • hVals

      List<byte @NonNull []> hVals(byte @NonNull [] key)
      Get entry set (values) of hash at field.
      Parameters:
      key - must not be null.
      Returns:
      empty List if key does not exist. null when used in pipeline / transaction.
      See Also:
    • hGetAll

      Map<byte @NonNull [], byte @NonNull []> hGetAll(byte @NonNull [] key)
      Get entire hash stored at key.
      Parameters:
      key - must not be null.
      Returns:
      empty Map if key does not exist or null when used in pipeline / transaction.
      See Also:
    • hRandField

      byte[] hRandField(byte @NonNull [] key)
      Return a random field from the hash stored at key.
      Parameters:
      key - must not be null.
      Returns:
      null if key does not exist or when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • hRandFieldWithValues

      Map.Entry<byte @NonNull [], byte @NonNull []> hRandFieldWithValues(byte @NonNull [] key)
      Return a random field from the hash along with its value stored at key.
      Parameters:
      key - must not be null.
      Returns:
      null if key does not exist or when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • hRandField

      List<byte @NonNull []> hRandField(byte @NonNull [] key, long count)
      Return a random field from the hash stored at key. If the provided count argument is positive, return a list of distinct fields, capped either at count or the hash size. If count is negative, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.
      Parameters:
      key - must not be null.
      count - number of fields to return.
      Returns:
      null if key does not exist or when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • hRandFieldWithValues

      List<@NonNull Map.Entry<byte @NonNull [], byte @NonNull []>> hRandFieldWithValues(byte @NonNull [] key, long count)
      Return a random field from the hash along with its value stored at key. If the provided count argument is positive, return a list of distinct fields, capped either at count or the hash size. If count is negative, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.
      Parameters:
      key - must not be null.
      count - number of fields to return.
      Returns:
      null if key does not exist or when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • hScan

      Cursor<@NonNull Map.Entry<byte @NonNull [], byte @NonNull []>> hScan(byte @NonNull [] key, ScanOptions options)
      Use a Cursor to iterate over entries in hash at key.
      Parameters:
      key - must not be null.
      options - must not be null.
      Returns:
      Since:
      1.4
      See Also:
    • hStrLen

      Long hStrLen(byte @NonNull [] key, byte @NonNull [] field)
      Returns the length of the value associated with field in the hash stored at key. If the key or the field do not exist, 0 is returned.
      Parameters:
      key - must not be null.
      field - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.1
      See Also:
    • applyHashFieldExpiration

      default List<@NonNull Long> applyHashFieldExpiration(byte @NonNull [] key, @NonNull Expiration expiration, byte @NonNull [] @NonNull ... fields)
      Apply a given Expiration to the given fields.
      Parameters:
      key - must not be null.
      expiration - the Expiration to apply.
      fields - the names of the fields to apply the expiration to.
      Returns:
      a List holding the command result for each field in order - 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set; -2 indicating there is no such field;
      Since:
      3.5
    • applyHashFieldExpiration

      default List<@NonNull Long> applyHashFieldExpiration(byte @NonNull [] key, @NonNull Expiration expiration, @NonNull ExpirationOptions options, byte @NonNull [] @NonNull ... fields)
      Parameters:
      key - must not be null.
      expiration - the Expiration to apply.
      options - additional options to be sent along with the command.
      fields - the names of the fields to apply the expiration to.
      Returns:
      a List holding the command result for each field in order - 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field;
      Since:
      3.5
    • hExpire

      default List<@NonNull Long> hExpire(byte @NonNull [] key, long seconds, byte @NonNull [] @NonNull ... fields)
      Set time to live for given fields in seconds.
      Parameters:
      key - must not be null.
      seconds - the amount of time after which the fields will be expired in seconds, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set; -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hExpire

      default List<@NonNull Long> hExpire(byte @NonNull [] key, @NonNull Duration ttl, byte @NonNull [] @NonNull ... fields)
      Set time to live for given fields.
      Parameters:
      key - must not be null.
      ttl - the amount of time after which the fields will be expired in seconds precision, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set; -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hExpire

      List<@NonNull Long> hExpire(byte @NonNull [] key, long seconds, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
      Set time to live for given fields in seconds.
      Parameters:
      key - must not be null.
      seconds - the amount of time after which the fields will be expired in seconds, must not be null.
      condition - the condition for expiration, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hpExpire

      default List<@NonNull Long> hpExpire(byte @NonNull [] key, long millis, byte @NonNull [] @NonNull ... fields)
      Set time to live for given fields in milliseconds.
      Parameters:
      key - must not be null.
      millis - the amount of time after which the fields will be expired in milliseconds, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set ; -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hpExpire

      default List<@NonNull Long> hpExpire(byte @NonNull [] key, @NonNull Duration ttl, byte @NonNull [] @NonNull ... fields)
      Set time to live for given fields in milliseconds.
      Parameters:
      key - must not be null.
      ttl - the amount of time after which the fields will be expired in milliseconds precision, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set; -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hpExpire

      List<@NonNull Long> hpExpire(byte @NonNull [] key, long millis, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
      Set time to live for given fields in milliseconds.
      Parameters:
      key - must not be null.
      millis - the amount of time after which the fields will be expired in milliseconds, must not be null.
      condition - the condition for expiration, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hExpireAt

      default List<Long> hExpireAt(byte @NonNull [] key, long unixTime, byte @NonNull [] @NonNull ... fields)
      Set the expiration for given field as a UNIX timestamp.
      Parameters:
      key - must not be null.
      unixTime - the moment in time in which the field expires, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set; -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hExpireAt

      List<@NonNull Long> hExpireAt(byte @NonNull [] key, long unixTime, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
      Set the expiration for given field as a UNIX timestamp.
      Parameters:
      key - must not be null.
      unixTime - the moment in time in which the field expires, must not be null.
      condition - the condition for expiration, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hpExpireAt

      default List<@NonNull Long> hpExpireAt(byte @NonNull [] key, long unixTimeInMillis, byte @NonNull [] @NonNull ... fields)
      Set the expiration for given field as a UNIX timestamp in milliseconds.
      Parameters:
      key - must not be null.
      unixTimeInMillis - the moment in time in which the field expires in milliseconds, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set; -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hpExpireAt

      List<@NonNull Long> hpExpireAt(byte @NonNull [] key, long unixTimeInMillis, @NonNull ExpirationOptions.Condition condition, byte @NonNull [] @NonNull ... fields)
      Set the expiration for given field as a UNIX timestamp in milliseconds.
      Parameters:
      key - must not be null.
      unixTimeInMillis - the moment in time in which the field expires in milliseconds, must not be null.
      condition - the condition for expiration, must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hPersist

      List<@NonNull Long> hPersist(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
      Remove the expiration from given field.
      Parameters:
      key - must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: 1 indicating expiration time is removed; -1 field has no expiration time to be removed; -2 indicating there is no such field; null when used in pipeline / transaction.null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hTtl

      List<@NonNull Long> hTtl(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
      Get the time to live for fields in seconds.
      Parameters:
      key - must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: the time to live in seconds; or a negative value to signal an error. The command returns -1 if the field exists but has no associated expiration time. The command returns -2 if the field does not exist; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hTtl

      List<@NonNull Long> hTtl(byte @NonNull [] key, @NonNull TimeUnit timeUnit, byte @NonNull [] @NonNull ... fields)
      Get the time to live for fields in and convert it to the given TimeUnit.
      Parameters:
      key - must not be null.
      timeUnit - must not be null.
      fields - must not be null.
      Returns:
      for each of the fields supplied - the time to live in the TimeUnit provided; or a negative value to signal an error. The command returns -1 if the key exists but has no associated expiration time. The command returns -2 if the key does not exist; null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • hpTtl

      List<@NonNull Long> hpTtl(byte @NonNull [] key, byte @NonNull [] @NonNull ... fields)
      Get the time to live for fields in milliseconds.
      Parameters:
      key - must not be null.
      fields - must not be null.
      Returns:
      a list of Long values for each of the fields provided: the time to live in seconds; or a negative value to signal an error. The command returns -1 if the key exists but has no associated expiration time. The command returns -2 if the key does not exist; null when used in pipeline / transaction.
      Since:
      3.5
      See Also: