Interface RedisZSet<E>

Type Parameters:
E - the type of elements in this collection.
All Superinterfaces:
BoundKeyOperations<String>, Collection<E>, Iterable<E>, RedisCollection<E>, RedisStore, Set<E>
All Known Implementing Classes:
DefaultRedisZSet

public interface RedisZSet<E> extends RedisCollection<E>, Set<E>
Redis ZSet (or sorted set (by weight)). Acts as a SortedSet based on the given priorities or weights associated with each item.

Since using a Comparator does not apply, a ZSet implements the SortedSet methods where applicable.

Author:
Costin Leau, Mark Paluch, Christoph Strobl, Andrey Shlykov
  • Method Details

    • create

      static <E> RedisZSet<E> create(String key, RedisOperations<String,E> operations)
      Constructs a new RedisZSet instance with a default score of 1.
      Parameters:
      key - Redis key of this set.
      operations - RedisOperations for the value type of this set.
      Since:
      2.6
    • create

      static <E> RedisZSet<E> create(String key, RedisOperations<String,E> operations, double defaultScore)
      Constructs a new RedisZSet instance.
      Parameters:
      key - Redis key of this set.
      operations - RedisOperations for the value type of this set.
      defaultScore -
      Since:
      2.6
    • diff

      Set<E> diff(RedisZSet<?> set)
      Diff this set and another RedisZSet.
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the values that differ.
      Since:
      2.6
    • diff

      Set<E> diff(Collection<? extends RedisZSet<?>> sets)
      Diff this set and other RedisZSets.
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the values that differ.
      Since:
      2.6
    • diffWithScores

      Set<ZSetOperations.TypedTuple<E>> diffWithScores(RedisZSet<?> set)
      Diff this set and another RedisZSet.
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the values that differ with their scores.
      Since:
      2.6
    • diffWithScores

      Set<ZSetOperations.TypedTuple<E>> diffWithScores(Collection<? extends RedisZSet<?>> sets)
      Diff this set and other RedisZSets.
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the values that differ with their scores.
      Since:
      2.6
    • diffAndStore

      RedisZSet<E> diffAndStore(RedisZSet<?> set, String destKey)
      Create a new RedisZSet by diffing this sorted set and RedisZSet and store result in destination destKey.
      Parameters:
      set - must not be null.
      destKey - must not be null.
      Returns:
      a new RedisZSet pointing at destKey.
      Since:
      2.6
    • diffAndStore

      RedisZSet<E> diffAndStore(Collection<? extends RedisZSet<?>> sets, String destKey)
      Create a new RedisZSet by diffing this sorted set and the collection RedisZSet and store result in destination destKey.
      Parameters:
      sets - must not be null.
      destKey - must not be null.
      Returns:
      a new RedisZSet pointing at destKey.
      Since:
      2.6
    • intersect

      Set<E> intersect(RedisZSet<?> set)
      Intersect this set and another RedisZSet.
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the intersecting values.
      Since:
      2.6
    • intersect

      Set<E> intersect(Collection<? extends RedisZSet<?>> sets)
      Intersect this set and other RedisZSets.
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the intersecting values.
      Since:
      2.6
    • intersectWithScores

      Set<ZSetOperations.TypedTuple<E>> intersectWithScores(RedisZSet<?> set)
      Intersect this set and another RedisZSet.
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the intersecting values with their scores.
      Since:
      2.6
    • intersectWithScores

      Set<ZSetOperations.TypedTuple<E>> intersectWithScores(Collection<? extends RedisZSet<?>> sets)
      Intersect this set and other RedisZSets.
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the intersecting values with their scores.
      Since:
      2.6
    • intersectAndStore

      RedisZSet<E> intersectAndStore(RedisZSet<?> set, String destKey)
      Create a new RedisZSet by intersecting this sorted set and RedisZSet and store result in destination destKey.
      Parameters:
      set - must not be null.
      destKey - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
    • intersectAndStore

      RedisZSet<E> intersectAndStore(Collection<? extends RedisZSet<?>> sets, String destKey)
      Create a new RedisZSet by intersecting this sorted set and the collection RedisZSet and store result in destination destKey.
      Parameters:
      sets - must not be null.
      destKey - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
    • union

      Set<E> union(RedisZSet<?> set)
      Union this set and another RedisZSet.
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the combined values.
      Since:
      2.6
    • union

      Set<E> union(Collection<? extends RedisZSet<?>> sets)
      Union this set and other RedisZSets.
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the combined values.
      Since:
      2.6
    • unionWithScores

      Set<ZSetOperations.TypedTuple<E>> unionWithScores(RedisZSet<?> set)
      Union this set and another RedisZSet.
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the combined values with their scores.
      Since:
      2.6
    • unionWithScores

      Set<ZSetOperations.TypedTuple<E>> unionWithScores(Collection<? extends RedisZSet<?>> sets)
      Union this set and other RedisZSets.
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the combined values with their scores.
      Since:
      2.6
    • unionAndStore

      RedisZSet<E> unionAndStore(RedisZSet<?> set, String destKey)
      Create a new RedisZSet by union this sorted set and RedisZSet and store result in destination destKey.
      Parameters:
      set - must not be null.
      destKey - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
    • unionAndStore

      RedisZSet<E> unionAndStore(Collection<? extends RedisZSet<?>> sets, String destKey)
      Create a new RedisZSet by union this sorted set and the collection RedisZSet and store result in destination destKey.
      Parameters:
      sets - must not be null.
      destKey - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
    • randomValue

      E randomValue()
      Get random element from the set.
      Returns:
      Since:
      2.6
    • range

      Set<E> range(long start, long end)
      Get elements between start and end from sorted set.
      Parameters:
      start -
      end -
      Returns:
    • reverseRange

      Set<E> reverseRange(long start, long end)
      Get elements in range from start to end from sorted set ordered from high to low.
      Parameters:
      start -
      end -
      Returns:
    • rangeByLex

      @Deprecated(since="3.0", forRemoval=true) default Set<E> rangeByLex(RedisZSetCommands.Range range)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 3.0. Please use rangeByLex(Range) instead.
      Get all elements with lexicographical ordering with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      Returns:
      Since:
      1.7
      See Also:
    • rangeByLex

      default Set<E> rangeByLex(Range<String> range)
      Get all elements with lexicographical ordering with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      Returns:
      Since:
      3.0
      See Also:
    • rangeByLex

      @Deprecated(since="3.0", forRemoval=true) default Set<E> rangeByLex(RedisZSetCommands.Range range, Limit limit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 3.0. Please use rangeByLex(Range, Limit) instead.
      Get all elements n elements, where n = Limit.getCount(), starting at Limit.getOffset() with lexicographical ordering having a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      limit - can be null.
      Returns:
      Since:
      1.7
      See Also:
    • rangeByLex

      Set<E> rangeByLex(Range<String> range, Limit limit)
      Get all elements n elements, where n = Limit.getCount(), starting at Limit.getOffset() with lexicographical ordering having a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      limit - can be null.
      Returns:
      Since:
      3.0
      See Also:
    • reverseRangeByLex

      @Deprecated(since="3.0", forRemoval=true) default Set<E> reverseRangeByLex(RedisZSetCommands.Range range)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 3.0. Please use reverseRangeByLex(Range, Limit) instead.
      Get all elements with reverse lexicographical ordering with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      Returns:
      Since:
      2.4
      See Also:
    • reverseRangeByLex

      default Set<E> reverseRangeByLex(Range<String> range)
      Get all elements with reverse lexicographical ordering with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      Returns:
      Since:
      3.0
      See Also:
    • reverseRangeByLex

      @Deprecated(since="3.0", forRemoval=true) default Set<E> reverseRangeByLex(RedisZSetCommands.Range range, Limit limit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 3.0. Please use reverseRangeByLex(Range, Limit) instead.
      Get all elements n elements, where n = Limit.getCount(), starting at Limit.getOffset() with reverse lexicographical ordering having a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      limit - can be null.
      Returns:
      Since:
      2.4
      See Also:
    • reverseRangeByLex

      Set<E> reverseRangeByLex(Range<String> range, Limit limit)
      Get all elements n elements, where n = Limit.getCount(), starting at Limit.getOffset() with reverse lexicographical ordering having a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      range - must not be null.
      limit - can be null.
      Returns:
      Since:
      3.0
      See Also:
    • rangeByScore

      Set<E> rangeByScore(double min, double max)
      Get elements where score is between min and max from sorted set.
      Parameters:
      min -
      max -
      Returns:
    • reverseRangeByScore

      Set<E> reverseRangeByScore(double min, double max)
      Get elements where score is between min and max from sorted set ordered from high to low.
      Parameters:
      min -
      max -
      Returns:
    • rangeWithScores

      Set<ZSetOperations.TypedTuple<E>> rangeWithScores(long start, long end)
      Get set of Tuples between start and end from sorted set.
      Parameters:
      start -
      end -
      Returns:
    • reverseRangeWithScores

      Set<ZSetOperations.TypedTuple<E>> reverseRangeWithScores(long start, long end)
      Get set of Tuples in range from start to end from sorted set ordered from high to low.
      Parameters:
      start -
      end -
      Returns:
    • rangeByScoreWithScores

      Set<ZSetOperations.TypedTuple<E>> rangeByScoreWithScores(double min, double max)
      Get set of Tuples where score is between min and max from sorted set.
      Parameters:
      min -
      max -
      Returns:
    • reverseRangeByScoreWithScores

      Set<ZSetOperations.TypedTuple<E>> reverseRangeByScoreWithScores(double min, double max)
      Get set of Tuples where score is between min and max from sorted set ordered from high to low.
      Parameters:
      min -
      max -
      Returns:
    • rangeAndStoreByLex

      default RedisZSet<E> rangeAndStoreByLex(String dstKey, Range<String> range)
      Store all elements at dstKey with lexicographical ordering from ZSET at the bound key with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
      See Also:
    • rangeAndStoreByLex

      RedisZSet<E> rangeAndStoreByLex(String dstKey, Range<String> range, Limit limit)
      Store n elements at dstKey, where n = Limit.getCount(), starting at Limit.getOffset() with lexicographical ordering from ZSET at the bound key with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
      See Also:
    • reverseRangeAndStoreByLex

      default RedisZSet<E> reverseRangeAndStoreByLex(String dstKey, Range<String> range)
      Store all elements at dstKey with reverse lexicographical ordering from ZSET at the bound key with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
      See Also:
    • reverseRangeAndStoreByLex

      RedisZSet<E> reverseRangeAndStoreByLex(String dstKey, Range<String> range, Limit limit)
      Store n elements at dstKey, where n = Limit.getCount(), starting at Limit.getOffset() with reverse lexicographical ordering from ZSET at the bound key with a value between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
      See Also:
    • rangeAndStoreByScore

      default RedisZSet<E> rangeAndStoreByScore(String dstKey, Range<? extends Number> range)
      Store all elements at dstKey with ordering by score from ZSET at the bound key with a score between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
      See Also:
    • rangeAndStoreByScore

      RedisZSet<E> rangeAndStoreByScore(String dstKey, Range<? extends Number> range, Limit limit)
      Store n elements at dstKey, where n = Limit.getCount(), starting at Limit.getOffset() with ordering by score from ZSET at the bound key with a score between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
      See Also:
    • reverseRangeAndStoreByScore

      default RedisZSet<E> reverseRangeAndStoreByScore(String dstKey, Range<? extends Number> range)
      Store all elements at dstKey with reverse ordering by score from ZSET at the bound key with a score between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
      See Also:
    • reverseRangeAndStoreByScore

      RedisZSet<E> reverseRangeAndStoreByScore(String dstKey, Range<? extends Number> range, Limit limit)
      Store n elements at dstKey, where n = Limit.getCount(), starting at Limit.getOffset() with reverse ordering by score from ZSET at the bound key with a score between Range.getLowerBound() and Range.getUpperBound().
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      Since:
      3.0
    • remove

      RedisZSet<E> remove(long start, long end)
      Remove elements in range between start and end from sorted set.
      Parameters:
      start -
      end -
      Returns:
      this set.
    • removeByLex

      RedisZSet<E> removeByLex(Range<String> range)
      Remove all elements in range.
      Parameters:
      range - must not be null.
      Returns:
      this set.
      Since:
      2.5
    • removeByScore

      RedisZSet<E> removeByScore(double min, double max)
      Remove elements with scores between min and max from sorted set with the bound key.
      Parameters:
      min -
      max -
      Returns:
      this set.
    • add

      boolean add(E e, double score)
      Adds an element to the set with the given score, or updates the score if the element exists.
      Parameters:
      e - element to add
      score - element score
      Returns:
      true if a new element was added, false otherwise (only the score has been updated)
    • add

      boolean add(E e)
      Adds an element to the set with a default score. Equivalent to add(e, getDefaultScore()). The score value is implementation specific.
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Set<E>
    • addIfAbsent

      default boolean addIfAbsent(E e)
      Adds an element to the set using the default score if the element does not already exists.
      Parameters:
      e - element to add
      Returns:
      true if a new element was added, false otherwise (only the score has been updated)
      Since:
      2.5
    • addIfAbsent

      boolean addIfAbsent(E e, double score)
      Adds an element to the set with the given score if the element does not already exists.
      Parameters:
      e - element to add
      score - element score
      Returns:
      true if a new element was added, false otherwise (only the score has been updated)
      Since:
      2.5
    • lexCount

      Long lexCount(Range<String> range)
      Count number of elements within sorted set with value between Range#min and Range#max applying lexicographical ordering.
      Parameters:
      range - must not be null.
      Returns:
      Since:
      2.4
      See Also:
    • score

      Double score(Object o)
      Returns the score of the given element. Returns null if the element is not contained by the set.
      Parameters:
      o - object
      Returns:
      the score associated with the given object
    • rank

      Long rank(Object o)
      Returns the rank (position) of the given element in the set, in ascending order. Returns null if the element is not contained by the set.
      Parameters:
      o - object
      Returns:
      rank of the given object
    • reverseRank

      Long reverseRank(Object o)
      Returns the rank (position) of the given element in the set, in descending order. Returns null if the element is not contained by the set.
      Parameters:
      o - object
      Returns:
      reverse rank of the given object
    • getDefaultScore

      Double getDefaultScore()
      Returns the default score used by this set.
      Returns:
      the default score used by the implementation.
    • first

      E first()
      Returns the first (lowest) element currently in this sorted set.
      Returns:
      the first (lowest) element currently in this sorted set.
      Throws:
      NoSuchElementException - sorted set is empty.
    • popFirst

      E popFirst()
      Removes the first (lowest) object at the top of this sorted set and returns that object as the value of this function.
      Returns:
      the first (lowest) element currently in this sorted set.
      Throws:
      NoSuchElementException - sorted set is empty.
      Since:
      2.6
    • popFirst

      E popFirst(long timeout, TimeUnit unit)
      Removes the first (lowest) object at the top of this sorted set and returns that object as the value of this function. Blocks connection until element available or timeout reached.
      Parameters:
      timeout -
      unit - must not be null.
      Returns:
      the first (lowest) element currently in this sorted set.
      Throws:
      NoSuchElementException - sorted set is empty.
      Since:
      2.6
    • last

      E last()
      Returns the last (highest) element currently in this sorted set.
      Returns:
      the last (highest) element currently in this sorted set.
      Throws:
      NoSuchElementException - sorted set is empty.
    • popLast

      E popLast()
      Removes the last (highest) object at the top of this sorted set and returns that object as the value of this function.
      Returns:
      the last (highest) element currently in this sorted set.
      Throws:
      NoSuchElementException - sorted set is empty.
      Since:
      2.6
    • popLast

      E popLast(long timeout, TimeUnit unit)
      Removes the last (highest) object at the top of this sorted set and returns that object as the value of this function. Blocks connection until element available or timeout reached.
      Parameters:
      timeout -
      unit - must not be null.
      Returns:
      the last (highest) element currently in this sorted set.
      Throws:
      NoSuchElementException - sorted set is empty.
      Since:
      2.6
    • scan

      Iterator<E> scan()
      Returns:
      Since:
      1.4