Interface ListOperations<K,V>


@NullUnmarked public interface ListOperations<K,V>
Redis list specific operations.
Author:
Costin Leau, David Liu, Thomas Darimont, Christoph Strobl, Mark Paluch, dengliming, Lee Jaeheon
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Value object representing the where from part for the LMOVE command.
    static class 
    Value object representing the where to from part for the LMOVE command.
  • Method Summary

    Modifier and Type
    Method
    Description
    default V
    getFirst(@NonNull K key)
    Returns the first element from the list at key.
    default V
    getLast(@NonNull K key)
    Returns the last element from the list at key.
    @NonNull RedisOperations<K,V>
     
    index(@NonNull K key, long index)
    Get element at index from list at key.
    indexOf(@NonNull K key, V value)
    Returns the index of the first occurrence of the specified value in the list at at key.
    lastIndexOf(@NonNull K key, V value)
    Returns the index of the last occurrence of the specified value in the list at at key.
    leftPop(@NonNull K key)
    Removes and returns first element in list stored at key.
    leftPop(@NonNull K key, long count)
    Removes and returns first elements in list stored at key.
    leftPop(@NonNull K key, long timeout, @NonNull TimeUnit unit)
    Removes and returns first element from lists stored at key .
    default V
    leftPop(@NonNull K key, @NonNull Duration timeout)
    Removes and returns first element from lists stored at key .
    leftPush(@NonNull K key, @NonNull V pivot, V value)
    Insert value to key before pivot.
    leftPush(@NonNull K key, V value)
    Prepend value to key.
    leftPushAll(@NonNull K key, @NonNull Collection<V> values)
    Prepend values to key.
    leftPushAll(@NonNull K key, V @NonNull ... values)
    Prepend values to key.
    leftPushIfPresent(@NonNull K key, V value)
    Prepend values to key only if the list exists.
    move(@NonNull K sourceKey, @NonNull RedisListCommands.Direction from, @NonNull K destinationKey, @NonNull RedisListCommands.Direction to)
    Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.
    move(@NonNull K sourceKey, @NonNull RedisListCommands.Direction from, @NonNull K destinationKey, @NonNull RedisListCommands.Direction to, long timeout, @NonNull TimeUnit unit)
    Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.
    default V
    move(@NonNull K sourceKey, @NonNull RedisListCommands.Direction from, @NonNull K destinationKey, @NonNull RedisListCommands.Direction to, @NonNull Duration timeout)
    Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.
    default V
    move(@NonNull ListOperations.MoveFrom<K> from, @NonNull ListOperations.MoveTo<K> to)
    Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.
    default V
    move(@NonNull ListOperations.MoveFrom<K> from, @NonNull ListOperations.MoveTo<K> to, @NonNull Duration timeout)
    Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.
    range(@NonNull K key, long start, long end)
    Get elements between begin and end from list at key.
    remove(@NonNull K key, long count, Object value)
    Removes the first count occurrences of value from the list stored at key.
    rightPop(@NonNull K key)
    Removes and returns last element in list stored at key.
    rightPop(@NonNull K key, long count)
    Removes and returns last elements in list stored at key.
    rightPop(@NonNull K key, long timeout, @NonNull TimeUnit unit)
    Removes and returns last element from lists stored at key.
    default V
    rightPop(@NonNull K key, @NonNull Duration timeout)
    Removes and returns last element from lists stored at key.
    rightPopAndLeftPush(@NonNull K sourceKey, @NonNull K destinationKey)
    Remove the last element from list at sourceKey, append it to destinationKey and return its value.
    rightPopAndLeftPush(@NonNull K sourceKey, @NonNull K destinationKey, long timeout, @NonNull TimeUnit unit)
    Remove the last element from list at sourceKey, append it to destinationKey and return its value.
    Blocks connection until element available or timeout reached.
    default V
    rightPopAndLeftPush(@NonNull K sourceKey, @NonNull K destinationKey, @NonNull Duration timeout)
    Remove the last element from list at sourceKey, append it to destinationKey and return its value.
    Blocks connection until element available or timeout reached.
    rightPush(@NonNull K key, @NonNull V pivot, V value)
    Insert value to key after pivot.
    rightPush(@NonNull K key, V value)
    Append value to key.
    rightPushAll(@NonNull K key, @NonNull Collection<V> values)
    Append values to key.
    rightPushAll(@NonNull K key, V @NonNull ... values)
    Append values to key.
    rightPushIfPresent(@NonNull K key, V value)
    Append values to key only if the list exists.
    void
    set(@NonNull K key, long index, V value)
    Set the value list element at index.
    size(@NonNull K key)
    Get the size of list stored at key.
    void
    trim(@NonNull K key, long start, long end)
    Trim list at key to elements between start and end.
  • Method Details

    • range

      List<V> range(@NonNull K key, long start, long end)
      Get elements between begin and end from list at key.
      Parameters:
      key - must not be null.
      start -
      end -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • trim

      void trim(@NonNull K key, long start, long end)
      Trim list at key to elements between start and end.
      Parameters:
      key - must not be null.
      start -
      end -
      See Also:
    • size

      Long size(@NonNull K key)
      Get the size of list stored at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • leftPush

      Long leftPush(@NonNull K key, V value)
      Prepend value to key.
      Parameters:
      key - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • leftPushAll

      Long leftPushAll(@NonNull K key, V @NonNull ... values)
      Prepend values to key.
      Parameters:
      key - must not be null.
      values -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • leftPushAll

      Long leftPushAll(@NonNull K key, @NonNull Collection<V> values)
      Prepend values to key.
      Parameters:
      key - must not be null.
      values - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      1.5
      See Also:
    • leftPushIfPresent

      Long leftPushIfPresent(@NonNull K key, V value)
      Prepend values to key only if the list exists.
      Parameters:
      key - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • leftPush

      Long leftPush(@NonNull K key, @NonNull V pivot, V value)
      Insert value to key before pivot.
      Parameters:
      key - must not be null.
      pivot - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • rightPush

      Long rightPush(@NonNull K key, V value)
      Append value to key.
      Parameters:
      key - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • rightPushAll

      Long rightPushAll(@NonNull K key, V @NonNull ... values)
      Append values to key.
      Parameters:
      key - must not be null.
      values -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • rightPushAll

      Long rightPushAll(@NonNull K key, @NonNull Collection<V> values)
      Append values to key.
      Parameters:
      key - must not be null.
      values -
      Returns:
      null when used in pipeline / transaction.
      Since:
      1.5
      See Also:
    • rightPushIfPresent

      Long rightPushIfPresent(@NonNull K key, V value)
      Append values to key only if the list exists.
      Parameters:
      key - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • rightPush

      Long rightPush(@NonNull K key, @NonNull V pivot, V value)
      Insert value to key after pivot.
      Parameters:
      key - must not be null.
      pivot - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • move

      default V move(@NonNull ListOperations.MoveFrom<K> from, @NonNull ListOperations.MoveTo<K> to)
      Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.
      Parameters:
      from - must not be null.
      to - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • move

      V move(@NonNull K sourceKey, @NonNull RedisListCommands.Direction from, @NonNull K destinationKey, @NonNull RedisListCommands.Direction to)
      Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.
      Parameters:
      sourceKey - must not be null.
      from - must not be null.
      destinationKey - must not be null.
      to - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • move

      default V move(@NonNull ListOperations.MoveFrom<K> from, @NonNull ListOperations.MoveTo<K> to, @NonNull Duration timeout)
      Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.

      Blocks connection until element available or timeout reached.

      Parameters:
      from - must not be null.
      to - must not be null.
      timeout - must not be null or negative.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • move

      default V move(@NonNull K sourceKey, @NonNull RedisListCommands.Direction from, @NonNull K destinationKey, @NonNull RedisListCommands.Direction to, @NonNull Duration timeout)
      Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.

      Blocks connection until element available or timeout reached.

      Parameters:
      sourceKey - must not be null.
      from - must not be null.
      destinationKey - must not be null.
      to - must not be null.
      timeout - must not be null or negative.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • move

      V move(@NonNull K sourceKey, @NonNull RedisListCommands.Direction from, @NonNull K destinationKey, @NonNull RedisListCommands.Direction to, long timeout, @NonNull TimeUnit unit)
      Atomically returns and removes the first/last element (head/tail depending on the from argument) of the list stored at sourceKey, and pushes the element at the first/last element (head/tail depending on the to argument) of the list stored at destinationKey.

      Blocks connection until element available or timeout reached.

      Parameters:
      sourceKey - must not be null.
      from - must not be null.
      destinationKey - must not be null.
      to - must not be null.
      timeout -
      unit -
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • set

      void set(@NonNull K key, long index, V value)
      Set the value list element at index.
      Parameters:
      key - must not be null.
      index -
      value -
      See Also:
    • remove

      Long remove(@NonNull K key, long count, Object value)
      Removes the first count occurrences of value from the list stored at key.
      Parameters:
      key - must not be null.
      count -
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • getFirst

      default V getFirst(@NonNull K key)
      Returns the first element from the list at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      3.4
    • getLast

      default V getLast(@NonNull K key)
      Returns the last element from the list at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      3.4
    • index

      V index(@NonNull K key, long index)
      Get element at index from list at key.
      Parameters:
      key - must not be null.
      index -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • indexOf

      Long indexOf(@NonNull K key, V value)
      Returns the index of the first occurrence of the specified value in the list at at key.
      Requires Redis 6.0.6 or newer.
      Parameters:
      key - must not be null.
      value - must not be null.
      Returns:
      null when used in pipeline / transaction or when not contained in list.
      Since:
      2.4
      See Also:
    • lastIndexOf

      Long lastIndexOf(@NonNull K key, V value)
      Returns the index of the last occurrence of the specified value in the list at at key.
      Requires Redis 6.0.6 or newer.
      Parameters:
      key - must not be null.
      value - must not be null.
      Returns:
      null when used in pipeline / transaction or when not contained in list.
      Since:
      2.4
      See Also:
    • leftPop

      V leftPop(@NonNull K key)
      Removes and returns first element in list stored at key.
      Parameters:
      key - must not be null.
      Returns:
      can be null.
      See Also:
    • leftPop

      List<V> leftPop(@NonNull K key, long count)
      Removes and returns first elements in list stored at key.
      Parameters:
      key - must not be null.
      count -
      Returns:
      can be null.
      Since:
      2.6
      See Also:
    • leftPop

      V leftPop(@NonNull K key, long timeout, @NonNull TimeUnit unit)
      Removes and returns first element from lists stored at key .
      Blocks connection until element available or timeout reached.
      Parameters:
      key - must not be null.
      timeout -
      unit - must not be null.
      Returns:
      can be null.
      See Also:
    • leftPop

      default V leftPop(@NonNull K key, @NonNull Duration timeout)
      Removes and returns first element from lists stored at key .
      Blocks connection until element available or timeout reached.
      Parameters:
      key - must not be null.
      timeout - must not be null.
      Returns:
      can be null.
      Throws:
      IllegalArgumentException - if the timeout is null or negative.
      Since:
      2.3
      See Also:
    • rightPop

      V rightPop(@NonNull K key)
      Removes and returns last element in list stored at key.
      Parameters:
      key - must not be null.
      Returns:
      can be null.
      See Also:
    • rightPop

      List<V> rightPop(@NonNull K key, long count)
      Removes and returns last elements in list stored at key.
      Parameters:
      key - must not be null.
      count -
      Returns:
      can be null.
      Since:
      2.6
      See Also:
    • rightPop

      V rightPop(@NonNull K key, long timeout, @NonNull TimeUnit unit)
      Removes and returns last element from lists stored at key.
      Blocks connection until element available or timeout reached.
      Parameters:
      key - must not be null.
      timeout -
      unit - must not be null.
      Returns:
      can be null.
      See Also:
    • rightPop

      default V rightPop(@NonNull K key, @NonNull Duration timeout)
      Removes and returns last element from lists stored at key.
      Blocks connection until element available or timeout reached.
      Parameters:
      key - must not be null.
      timeout - must not be null.
      Returns:
      can be null.
      Since:
      2.3
      See Also:
    • rightPopAndLeftPush

      V rightPopAndLeftPush(@NonNull K sourceKey, @NonNull K destinationKey)
      Remove the last element from list at sourceKey, append it to destinationKey and return its value.
      Parameters:
      sourceKey - must not be null.
      destinationKey - must not be null.
      Returns:
      can be null.
      See Also:
    • rightPopAndLeftPush

      V rightPopAndLeftPush(@NonNull K sourceKey, @NonNull K destinationKey, long timeout, @NonNull TimeUnit unit)
      Remove the last element from list at sourceKey, append it to destinationKey and return its value.
      Blocks connection until element available or timeout reached.
      Parameters:
      sourceKey - must not be null.
      destinationKey - must not be null.
      timeout -
      unit - must not be null.
      Returns:
      can be null.
      See Also:
    • rightPopAndLeftPush

      default V rightPopAndLeftPush(@NonNull K sourceKey, @NonNull K destinationKey, @NonNull Duration timeout)
      Remove the last element from list at sourceKey, append it to destinationKey and return its value.
      Blocks connection until element available or timeout reached.
      Parameters:
      sourceKey - must not be null.
      destinationKey - must not be null.
      timeout - must not be null.
      Returns:
      can be null.
      Throws:
      IllegalArgumentException - if the timeout is null or negative.
      Since:
      2.3
      See Also:
    • getOperations

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