Interface SetOperations<K,V>


@NullUnmarked public interface SetOperations<K,V>
Redis set specific operations.
Author:
Costin Leau, Christoph Strobl, Mark Paluch, Roman Bezpalko, Mingi Lee
  • Method Summary

    Modifier and Type
    Method
    Description
    add(@NonNull K key, V @NonNull ... values)
    Add given values to set at key.
    Set<@NonNull V>
    difference(@NonNull Collection<@NonNull K> keys)
    Diff all sets for given keys.
    Set<@NonNull V>
    difference(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys)
    Diff all sets for given key and otherKeys.
    Set<@NonNull V>
    difference(@NonNull K key, @NonNull K otherKey)
    Diff all sets for given key and otherKey.
    differenceAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey)
    Diff all sets for given keys and store result in destKey.
    differenceAndStore(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys, @NonNull K destKey)
    Diff all sets for given key and otherKeys and store result in destKey.
    differenceAndStore(@NonNull K key, @NonNull K otherKey, @NonNull K destKey)
    Diff all sets for given key and otherKey and store result in destKey.
    Set<@NonNull V>
    distinctRandomMembers(@NonNull K key, long count)
    Get count distinct random elements from set at key.
    @NonNull RedisOperations<K,V>
     
    Set<@NonNull V>
    intersect(@NonNull Collection<K> keys)
    Returns the members intersecting all given sets at keys.
    Set<@NonNull V>
    intersect(@NonNull K key, @NonNull Collection<K> otherKeys)
    Returns the members intersecting all given sets at key and otherKeys.
    Set<@NonNull V>
    intersect(@NonNull K key, @NonNull K otherKey)
    Returns the members intersecting all given sets at key and otherKey.
    intersectAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey)
    Intersect all given sets at keys and store result in destKey.
    intersectAndStore(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys, @NonNull K destKey)
    Intersect all given sets at key and otherKeys and store result in destKey.
    intersectAndStore(@NonNull K key, @NonNull K otherKey, @NonNull K destKey)
    Intersect all given sets at key and otherKey and store result in destKey.
    intersectSize(@NonNull Collection<@NonNull K> keys)
    Returns the cardinality of the set which would result from the intersection of all given sets at keys.
    intersectSize(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys)
    Returns the cardinality of the set which would result from the intersection of key and otherKeys.
    intersectSize(@NonNull K key, @NonNull K otherKey)
    Returns the cardinality of the set which would result from the intersection of key and otherKey.
    isMember(@NonNull K key, Object o)
    Check if set at key contains value.
    isMember(@NonNull K key, Object @NonNull ... objects)
    Check if set at key contains one or more values.
    Set<@NonNull V>
    members(@NonNull K key)
    Get all elements of set at key.
    move(@NonNull K key, V value, @NonNull K destKey)
    Move value from key to destKey
    pop(@NonNull K key)
    Remove and return a random member from set at key.
    List<@NonNull V>
    pop(@NonNull K key, long count)
    Remove and return count random members from set at key.
    randomMember(@NonNull K key)
    Get random element from set at key.
    List<@NonNull V>
    randomMembers(@NonNull K key, long count)
    Get count random elements from set at key.
    remove(@NonNull K key, Object @NonNull ... values)
    Remove given values from set at key and return the number of removed elements.
    @NonNull Cursor<@NonNull V>
    scan(@NonNull K key, @NonNull ScanOptions options)
    Use a Cursor to iterate over entries set at key.
    size(@NonNull K key)
    Get size of set at key.
    Set<@NonNull V>
    union(@NonNull Collection<@NonNull K> keys)
    Union all sets at given keys.
    Set<@NonNull V>
    union(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys)
    Union all sets at given keys and otherKeys.
    Set<@NonNull V>
    union(@NonNull K key, @NonNull K otherKey)
    Union all sets at given keys and otherKey.
    unionAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey)
    Union all sets at given keys and store result in destKey.
    unionAndStore(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys, @NonNull K destKey)
    Union all sets at given key and otherKeys and store result in destKey.
    unionAndStore(@NonNull K key, @NonNull K otherKey, @NonNull K destKey)
    Union all sets at given key and otherKey and store result in destKey.
  • Method Details

    • add

      Long add(@NonNull K key, V @NonNull ... values)
      Add given values to set at key.
      Parameters:
      key - must not be null.
      values -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • remove

      Long remove(@NonNull K key, Object @NonNull ... values)
      Remove given values from set at key and return the number of removed elements.
      Parameters:
      key - must not be null.
      values -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • pop

      V pop(@NonNull K key)
      Remove and return a random member from set at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • pop

      List<@NonNull V> pop(@NonNull K key, long count)
      Remove and return count random members from set at key.
      Parameters:
      key - must not be null.
      count - number of random members to pop from the set.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.0
      See Also:
    • move

      Boolean move(@NonNull K key, V value, @NonNull K destKey)
      Move value from key to destKey
      Parameters:
      key - must not be null.
      value -
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • size

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

      Boolean isMember(@NonNull K key, Object o)
      Check if set at key contains value.
      Parameters:
      key - must not be null.
      o -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • isMember

      Map<Object,Boolean> isMember(@NonNull K key, Object @NonNull ... objects)
      Check if set at key contains one or more values.
      Parameters:
      key - must not be null.
      objects -
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • intersect

      Set<@NonNull V> intersect(@NonNull K key, @NonNull K otherKey)
      Returns the members intersecting all given sets at key and otherKey.
      Parameters:
      key - must not be null.
      otherKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • intersect

      Set<@NonNull V> intersect(@NonNull K key, @NonNull Collection<K> otherKeys)
      Returns the members intersecting all given sets at key and otherKeys.
      Parameters:
      key - must not be null.
      otherKeys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • intersect

      Set<@NonNull V> intersect(@NonNull Collection<K> keys)
      Returns the members intersecting all given sets at keys.
      Parameters:
      keys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.2
      See Also:
    • intersectAndStore

      Long intersectAndStore(@NonNull K key, @NonNull K otherKey, @NonNull K destKey)
      Intersect all given sets at key and otherKey and store result in destKey.
      Parameters:
      key - must not be null.
      otherKey - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • intersectAndStore

      Long intersectAndStore(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys, @NonNull K destKey)
      Intersect all given sets at key and otherKeys and store result in destKey.
      Parameters:
      key - must not be null.
      otherKeys - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • intersectAndStore

      Long intersectAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey)
      Intersect all given sets at keys and store result in destKey.
      Parameters:
      keys - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.2
      See Also:
    • intersectSize

      Long intersectSize(@NonNull K key, @NonNull K otherKey)
      Returns the cardinality of the set which would result from the intersection of key and otherKey.
      Parameters:
      key - must not be null.
      otherKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      4.0
      See Also:
    • intersectSize

      Long intersectSize(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys)
      Returns the cardinality of the set which would result from the intersection of key and otherKeys.
      Parameters:
      key - must not be null.
      otherKeys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      4.0
      See Also:
    • intersectSize

      Long intersectSize(@NonNull Collection<@NonNull K> keys)
      Returns the cardinality of the set which would result from the intersection of all given sets at keys.
      Parameters:
      keys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      4.0
      See Also:
    • union

      Set<@NonNull V> union(@NonNull K key, @NonNull K otherKey)
      Union all sets at given keys and otherKey.
      Parameters:
      key - must not be null.
      otherKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • union

      Set<@NonNull V> union(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys)
      Union all sets at given keys and otherKeys.
      Parameters:
      key - must not be null.
      otherKeys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • union

      Set<@NonNull V> union(@NonNull Collection<@NonNull K> keys)
      Union all sets at given keys.
      Parameters:
      keys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.2
      See Also:
    • unionAndStore

      Long unionAndStore(@NonNull K key, @NonNull K otherKey, @NonNull K destKey)
      Union all sets at given key and otherKey and store result in destKey.
      Parameters:
      key - must not be null.
      otherKey - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • unionAndStore

      Long unionAndStore(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys, @NonNull K destKey)
      Union all sets at given key and otherKeys and store result in destKey.
      Parameters:
      key - must not be null.
      otherKeys - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • unionAndStore

      Long unionAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey)
      Union all sets at given keys and store result in destKey.
      Parameters:
      keys - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.2
      See Also:
    • difference

      Set<@NonNull V> difference(@NonNull K key, @NonNull K otherKey)
      Diff all sets for given key and otherKey.
      Parameters:
      key - must not be null.
      otherKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • difference

      Set<@NonNull V> difference(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys)
      Diff all sets for given key and otherKeys.
      Parameters:
      key - must not be null.
      otherKeys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • difference

      Set<@NonNull V> difference(@NonNull Collection<@NonNull K> keys)
      Diff all sets for given keys.
      Parameters:
      keys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.2
      See Also:
    • differenceAndStore

      Long differenceAndStore(@NonNull K key, @NonNull K otherKey, @NonNull K destKey)
      Diff all sets for given key and otherKey and store result in destKey.
      Parameters:
      key - must not be null.
      otherKey - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • differenceAndStore

      Long differenceAndStore(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys, @NonNull K destKey)
      Diff all sets for given key and otherKeys and store result in destKey.
      Parameters:
      key - must not be null.
      otherKeys - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • differenceAndStore

      Long differenceAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey)
      Diff all sets for given keys and store result in destKey.
      Parameters:
      keys - must not be null.
      destKey - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.2
      See Also:
    • members

      Set<@NonNull V> members(@NonNull K key)
      Get all elements of set at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • randomMember

      V randomMember(@NonNull K key)
      Get random element from set at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • distinctRandomMembers

      Set<@NonNull V> distinctRandomMembers(@NonNull K key, long count)
      Get count distinct random elements from set at key.
      Parameters:
      key - must not be null.
      count - nr of members to return
      Returns:
      empty Set if key does not exist.
      Throws:
      IllegalArgumentException - if count is negative.
      See Also:
    • randomMembers

      List<@NonNull V> randomMembers(@NonNull K key, long count)
      Get count random elements from set at key.
      Parameters:
      key - must not be null.
      count - nr of members to return.
      Returns:
      empty List if key does not exist or null when used in pipeline / transaction.
      Throws:
      IllegalArgumentException - if count is negative.
      See Also:
    • scan

      @NonNull Cursor<@NonNull V> scan(@NonNull K key, @NonNull ScanOptions options)
      Use a Cursor to iterate over entries set at key.
      Important: Call CloseableIterator.close() when done to avoid resource leaks.
      Parameters:
      key -
      options - must not 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
    • getOperations

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