Interface RedisHashCommands

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

public interface RedisHashCommands
Hash-specific commands supported by Redis.
Author:
Costin Leau, Christoph Strobl, Mark Paluch
  • Method Summary

    Modifier and Type
    Method
    Description
    hDel(byte[] key, byte[]... fields)
    Delete given hash fields.
    hExists(byte[] key, byte[] field)
    Determine if given hash field exists.
    byte[]
    hGet(byte[] key, byte[] field)
    Get value for given field from hash at key.
    Map<byte[],byte[]>
    hGetAll(byte[] key)
    Get entire hash stored at key.
    hIncrBy(byte[] key, byte[] field, double delta)
    Increment value of a hash field by the given delta.
    hIncrBy(byte[] key, byte[] field, long delta)
    Increment value of a hash field by the given delta.
    Set<byte[]>
    hKeys(byte[] key)
    Get key set (fields) of hash at key.
    hLen(byte[] key)
    Get size of hash at key.
    List<byte[]>
    hMGet(byte[] key, byte[]... fields)
    Get values for given fields from hash at key.
    void
    hMSet(byte[] key, Map<byte[],byte[]> hashes)
    Set multiple hash fields to multiple values using data provided in hashes
    byte[]
    hRandField(byte[] key)
    Return a random field from the hash stored at key.
    List<byte[]>
    hRandField(byte[] key, long count)
    Return a random field from the hash stored at key.
    Map.Entry<byte[],byte[]>
    Return a random field from the hash along with its value stored at key.
    List<Map.Entry<byte[],byte[]>>
    hRandFieldWithValues(byte[] key, long count)
    Return a random field from the hash along with its value stored at key.
    Cursor<Map.Entry<byte[],byte[]>>
    hScan(byte[] key, ScanOptions options)
    Use a Cursor to iterate over entries in hash at key.
    hSet(byte[] key, byte[] field, byte[] value)
    Set the value of a hash field.
    hSetNX(byte[] key, byte[] field, byte[] value)
    Set the value of a hash field only if field does not exist.
    hStrLen(byte[] key, byte[] field)
    Returns the length of the value associated with field in the hash stored at key.
    List<byte[]>
    hVals(byte[] key)
    Get entry set (values) of hash at field.
  • Method Details

    • hSet

      @Nullable Boolean hSet(byte[] key, byte[] field, byte[] 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

      @Nullable Boolean hSetNX(byte[] key, byte[] field, byte[] 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

      @Nullable byte[] hGet(byte[] key, byte[] 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

      @Nullable List<byte[]> hMGet(byte[] key, byte[]... 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[] 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

      @Nullable Long hIncrBy(byte[] key, byte[] 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

      @Nullable Double hIncrBy(byte[] key, byte[] 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

      @Nullable Boolean hExists(byte[] key, byte[] 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

      @Nullable Long hDel(byte[] key, byte[]... 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

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

      @Nullable Set<byte[]> hKeys(byte[] 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

      @Nullable List<byte[]> hVals(byte[] 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

      @Nullable Map<byte[],byte[]> hGetAll(byte[] 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

      @Nullable byte[] hRandField(byte[] 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

      @Nullable Map.Entry<byte[],byte[]> hRandFieldWithValues(byte[] 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

      @Nullable List<byte[]> hRandField(byte[] 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

      @Nullable List<Map.Entry<byte[],byte[]>> hRandFieldWithValues(byte[] 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<Map.Entry<byte[],byte[]>> hScan(byte[] 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

      @Nullable Long hStrLen(byte[] key, byte[] 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: