Interface HashOperations<H,HK,HV>


@NullUnmarked public interface HashOperations<H,HK,HV>
Redis map specific operations working on a hash.
Author:
Costin Leau, Christoph Strobl, Ninad Divadkar, Tihomir Mateev, Viktoriya Kutsarova
  • Method Details

    • delete

      Long delete(@NonNull H key, @NonNull Object @NonNull ... hashKeys)
      Delete given hash hashKeys.
      Parameters:
      key - must not be null.
      hashKeys - must not be null.
      Returns:
      null when used in pipeline / transaction.
    • hasKey

      Boolean hasKey(@NonNull H key, @NonNull Object hashKey)
      Determine if given hash hashKey exists.
      Parameters:
      key - must not be null.
      hashKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
    • get

      HV get(@NonNull H key, @NonNull Object hashKey)
      Get value for given hashKey from hash at key.
      Parameters:
      key - must not be null.
      hashKey - must not be null.
      Returns:
      null when key or hashKey does not exist or used in pipeline / transaction.
    • multiGet

      List<HV> multiGet(@NonNull H key, @NonNull Collection<@NonNull HK> hashKeys)
      Get values for given hashKeys 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.
      hashKeys - must not be null.
      Returns:
      null when used in pipeline / transaction.
    • getAndDelete

      List<HV> getAndDelete(@NonNull H key, @NonNull Collection<@NonNull HK> hashKeys)
      Get and remove the value for given hashKeys 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.
      hashKeys - must not be null.
      Returns:
      list of values for the given fields or null when used in pipeline / transaction.
      Since:
      4.0
      See Also:
    • getAndExpire

      List<HV> getAndExpire(@NonNull H key, @Nullable Expiration expiration, @NonNull Collection<@NonNull HK> hashKeys)
      Get and optionally expire the value for given hashKeys 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.
      expiration - is optional.
      hashKeys - must not be null.
      Returns:
      list of values for the given fields or null when used in pipeline / transaction.
      Since:
      4.0
      See Also:
    • putAndExpire

      Boolean putAndExpire(@NonNull H key, @NonNull Map<? extends @NonNull HK, ? extends HV> m, @NonNull RedisHashCommands.HashFieldSetOption condition, @Nullable Expiration expiration)
      Set multiple hash fields to multiple values using data provided in m with optional condition and expiration.
      Parameters:
      key - must not be null.
      m - must not be null.
      condition - must not be .
      expiration - is optional.
      Returns:
      whether all fields were set or null when used in pipeline / transaction.
      Since:
      4.0
      See Also:
    • increment

      Long increment(@NonNull H key, @NonNull HK hashKey, long delta)
      Increment value of a hash hashKey by the given delta.
      Parameters:
      key - must not be null.
      hashKey - must not be null.
      delta -
      Returns:
      null when used in pipeline / transaction.
    • increment

      Double increment(@NonNull H key, @NonNull HK hashKey, double delta)
      Increment value of a hash hashKey by the given delta.
      Parameters:
      key - must not be null.
      hashKey - must not be null.
      delta -
      Returns:
      null when used in pipeline / transaction.
    • randomKey

      HK randomKey(@NonNull H key)
      Return a random hash key 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:
    • randomEntry

      Map.Entry<@NonNull HK, HV> randomEntry(@NonNull H key)
      Return a random entry 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:
    • randomKeys

      List<@NonNull HK> randomKeys(@NonNull H key, long count)
      Return random hash keys from the hash stored at key. If the provided count argument is positive, return a list of distinct hash keys, capped either at count or the hash size. If count is negative, the behavior changes and the command is allowed to return the same hash key 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:
    • randomEntries

      Map<@NonNull HK, HV> randomEntries(@NonNull H key, long count)
      Return a random entries from the hash stored at key.
      Parameters:
      key - must not be null.
      count - number of fields to return. Must be positive.
      Returns:
      null if key does not exist or when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • keys

      Set<@NonNull HK> keys(@NonNull H key)
      Get key set (fields) of hash at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
    • lengthOfValue

      Long lengthOfValue(@NonNull H key, @NonNull HK hashKey)
      Returns the length of the value associated with hashKey. If either the key or the hashKey do not exist, 0 is returned.
      Parameters:
      key - must not be null.
      hashKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.1
    • size

      Long size(@NonNull H key)
      Get size of hash at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
    • putAll

      void putAll(@NonNull H key, @NonNull Map<? extends @NonNull HK, ? extends HV> m)
      Set multiple hash fields to multiple values using data provided in m.
      Parameters:
      key - must not be null.
      m - must not be null.
    • put

      void put(@NonNull H key, @NonNull HK hashKey, HV value)
      Set the value of a hash hashKey.
      Parameters:
      key - must not be null.
      hashKey - must not be null.
      value -
    • putIfAbsent

      Boolean putIfAbsent(@NonNull H key, @NonNull HK hashKey, HV value)
      Set the value of a hash hashKey only if hashKey does not exist.
      Parameters:
      key - must not be null.
      hashKey - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
    • values

      List<HV> values(@NonNull H key)
      Get entry set (values) of hash at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
    • entries

      Map<@NonNull HK, HV> entries(@NonNull H key)
      Get entire hash stored at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
    • scan

      @NonNull Cursor<Map.Entry<@NonNull HK, HV>> scan(@NonNull H key, @Nullable ScanOptions options)
      Use a Cursor to iterate over entries in hash at key.
      Important: Call CloseableIterator.close() when done to avoid resource leaks.
      Parameters:
      key - must not be null.
      options - can be null.
      Returns:
      the result cursor providing access to the scan result. Must be closed once fully processed (e.g. through a try-with-resources clause).
      Since:
      1.4
    • expire

      ExpireChanges<@NonNull HK> expire(@NonNull H key, @NonNull Duration timeout, @NonNull Collection<@NonNull HK> hashKeys)
      Set time to live for given hashKey .
      Parameters:
      key - must not be null.
      timeout - the amount of time after which the key will be expired, must not be null.
      hashKeys - must not be null.
      Returns:
      changes to the hash fields. null when used in pipeline / transaction.
      Throws:
      IllegalArgumentException - if the timeout is null.
      Since:
      3.5
      See Also:
    • expireAt

      ExpireChanges<@NonNull HK> expireAt(@NonNull H key, @NonNull Instant expireAt, @NonNull Collection<@NonNull HK> hashKeys)
      Set the expiration for given hashKeys as a date timestamp.
      Parameters:
      key - must not be null.
      expireAt - must not be null.
      hashKeys - must not be null.
      Returns:
      changes to the hash fields. null when used in pipeline / transaction.
      Throws:
      IllegalArgumentException - if the instant is null or too large to represent as a Date.
      Since:
      3.5
      See Also:
    • expire

      ExpireChanges<@NonNull HK> expire(@NonNull H key, @NonNull Expiration expiration, @NonNull ExpirationOptions options, @NonNull Collection<@NonNull HK> hashKeys)
      Apply the expiration for given hashKeys.
      Parameters:
      key - must not be null.
      expiration - must not be null.
      options - must not be null.
      hashKeys - must not be null.
      Returns:
      changes to the hash fields. null when used in pipeline / transaction.
      Throws:
      IllegalArgumentException - if the instant is null or too large to represent as a Date.
      Since:
      3.5
      See Also:
    • persist

      ExpireChanges<@NonNull HK> persist(@NonNull H key, @NonNull Collection<@NonNull HK> hashKeys)
      Remove the expiration from given hashKeys .
      Parameters:
      key - must not be null.
      hashKeys - must not be null.
      Returns:
      changes to the hash fields. null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • getTimeToLive

      default Expirations<@NonNull HK> getTimeToLive(@NonNull H key, Collection<@NonNull HK> hashKeys)
      Get the time to live for hashKeys in seconds.
      Parameters:
      key - must not be null.
      hashKeys - must not be null.
      Returns:
      the actual expirations in seconds for the hash fields. null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • getTimeToLive

      Expirations<@NonNull HK> getTimeToLive(@NonNull H key, @NonNull TimeUnit timeUnit, @NonNull Collection<@NonNull HK> hashKeys)
      Get the time to live for hashKeys and convert it to the given TimeUnit.
      Parameters:
      key - must not be null.
      timeUnit - must not be null.
      hashKeys - must not be null.
      Returns:
      the actual expirations for the hash fields. null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • expiration

      default @NonNull BoundHashFieldExpirationOperations<HK> expiration(@NonNull H key)
      Returns a bound operations object to perform operations on the hash field expiration for all hash fields at key. Operations on the expiration object obtain keys at the time of invoking any expiration operation.
      Parameters:
      key - must not be null.
      Returns:
      the bound operations object to perform operations on the hash field expiration.
      Since:
      3.5
    • expiration

      default @NonNull BoundHashFieldExpirationOperations<HK> expiration(@NonNull H key, @NonNull HK @NonNull ... hashFields)
      Returns a bound operations object to perform operations on the hash field expiration for all hash fields at key for the given hash fields.
      Parameters:
      hashFields - collection of hash fields to operate on.
      Returns:
      the bound operations object to perform operations on the hash field expiration.
      Since:
      3.5
    • expiration

      default @NonNull BoundHashFieldExpirationOperations<HK> expiration(@NonNull H key, @NonNull Collection<@NonNull HK> hashFields)
      Returns a bound operations object to perform operations on the hash field expiration for all hash fields at key for the given hash fields.
      Parameters:
      hashFields - collection of hash fields to operate on.
      Returns:
      the bound operations object to perform operations on the hash field expiration.
      Since:
      3.5
    • getOperations

      @NonNull RedisOperations<H,?> getOperations()
      Returns:
      the underlying RedisOperations used to execute commands.