Class DefaultRedisZSet<E>

java.lang.Object
java.util.AbstractCollection<E>
org.springframework.data.redis.support.collections.AbstractRedisCollection<E>
org.springframework.data.redis.support.collections.DefaultRedisZSet<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>, BoundKeyOperations<String>, RedisCollection<E>, RedisStore, RedisZSet<E>

public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements RedisZSet<E>
Default implementation for RedisZSet. Note that the collection support works only with normal, non-pipeline/multi-exec connections as it requires a reply to be sent right away.
Author:
Costin Leau, Christoph Strobl, Mark Paluch, Andrey Shlykov
  • Constructor Details

  • Method Details

    • diff

      public Set<E> diff(RedisZSet<?> set)
      Description copied from interface: RedisZSet
      Diff this set and another RedisZSet.
      Specified by:
      diff in interface RedisZSet<E>
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the values that differ.
    • diff

      public Set<E> diff(Collection<? extends RedisZSet<?>> sets)
      Description copied from interface: RedisZSet
      Diff this set and other RedisZSets.
      Specified by:
      diff in interface RedisZSet<E>
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the values that differ.
    • diffWithScores

      public Set<ZSetOperations.TypedTuple<E>> diffWithScores(RedisZSet<?> set)
      Description copied from interface: RedisZSet
      Diff this set and another RedisZSet.
      Specified by:
      diffWithScores in interface RedisZSet<E>
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the values that differ with their scores.
    • diffWithScores

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

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

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

      public Set<E> intersect(RedisZSet<?> set)
      Description copied from interface: RedisZSet
      Intersect this set and another RedisZSet.
      Specified by:
      intersect in interface RedisZSet<E>
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the intersecting values.
    • intersect

      public Set<E> intersect(Collection<? extends RedisZSet<?>> sets)
      Description copied from interface: RedisZSet
      Intersect this set and other RedisZSets.
      Specified by:
      intersect in interface RedisZSet<E>
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the intersecting values.
    • intersectWithScores

      public Set<ZSetOperations.TypedTuple<E>> intersectWithScores(RedisZSet<?> set)
      Description copied from interface: RedisZSet
      Intersect this set and another RedisZSet.
      Specified by:
      intersectWithScores in interface RedisZSet<E>
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the intersecting values with their scores.
    • intersectWithScores

      public Set<ZSetOperations.TypedTuple<E>> intersectWithScores(Collection<? extends RedisZSet<?>> sets)
      Description copied from interface: RedisZSet
      Intersect this set and other RedisZSets.
      Specified by:
      intersectWithScores in interface RedisZSet<E>
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the intersecting values with their scores.
    • intersectAndStore

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

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

      public Set<E> union(RedisZSet<?> set)
      Description copied from interface: RedisZSet
      Union this set and another RedisZSet.
      Specified by:
      union in interface RedisZSet<E>
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the combined values.
    • union

      public Set<E> union(Collection<? extends RedisZSet<?>> sets)
      Description copied from interface: RedisZSet
      Union this set and other RedisZSets.
      Specified by:
      union in interface RedisZSet<E>
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the combined values.
    • unionWithScores

      public Set<ZSetOperations.TypedTuple<E>> unionWithScores(RedisZSet<?> set)
      Description copied from interface: RedisZSet
      Union this set and another RedisZSet.
      Specified by:
      unionWithScores in interface RedisZSet<E>
      Parameters:
      set - must not be null.
      Returns:
      a Set containing the combined values with their scores.
    • unionWithScores

      public Set<ZSetOperations.TypedTuple<E>> unionWithScores(Collection<? extends RedisZSet<?>> sets)
      Description copied from interface: RedisZSet
      Union this set and other RedisZSets.
      Specified by:
      unionWithScores in interface RedisZSet<E>
      Parameters:
      sets - must not be null.
      Returns:
      a Set containing the combined values with their scores.
    • unionAndStore

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

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

      public E randomValue()
      Description copied from interface: RedisZSet
      Get random element from the set.
      Specified by:
      randomValue in interface RedisZSet<E>
      Returns:
    • range

      public Set<E> range(long start, long end)
      Description copied from interface: RedisZSet
      Get elements between start and end from sorted set.
      Specified by:
      range in interface RedisZSet<E>
      Returns:
    • reverseRange

      public Set<E> reverseRange(long start, long end)
      Description copied from interface: RedisZSet
      Get elements in range from start to end from sorted set ordered from high to low.
      Specified by:
      reverseRange in interface RedisZSet<E>
      Returns:
    • rangeByLex

      public Set<E> rangeByLex(org.springframework.data.domain.Range<String> range, Limit limit)
      Description copied from interface: RedisZSet
      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().
      Specified by:
      rangeByLex in interface RedisZSet<E>
      Parameters:
      range - must not be null.
      limit - can be null.
      Returns:
      See Also:
    • reverseRangeByLex

      public Set<E> reverseRangeByLex(org.springframework.data.domain.Range<String> range, Limit limit)
      Description copied from interface: RedisZSet
      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().
      Specified by:
      reverseRangeByLex in interface RedisZSet<E>
      Parameters:
      range - must not be null.
      limit - can be null.
      Returns:
      See Also:
    • rangeByScore

      public Set<E> rangeByScore(double min, double max)
      Description copied from interface: RedisZSet
      Get elements where score is between min and max from sorted set.
      Specified by:
      rangeByScore in interface RedisZSet<E>
      Returns:
    • reverseRangeByScore

      public Set<E> reverseRangeByScore(double min, double max)
      Description copied from interface: RedisZSet
      Get elements where score is between min and max from sorted set ordered from high to low.
      Specified by:
      reverseRangeByScore in interface RedisZSet<E>
      Returns:
    • rangeByScoreWithScores

      public Set<ZSetOperations.TypedTuple<E>> rangeByScoreWithScores(double min, double max)
      Description copied from interface: RedisZSet
      Get set of Tuples where score is between min and max from sorted set.
      Specified by:
      rangeByScoreWithScores in interface RedisZSet<E>
      Returns:
    • rangeWithScores

      public Set<ZSetOperations.TypedTuple<E>> rangeWithScores(long start, long end)
      Description copied from interface: RedisZSet
      Get set of Tuples between start and end from sorted set.
      Specified by:
      rangeWithScores in interface RedisZSet<E>
      Returns:
    • reverseRangeByScoreWithScores

      public Set<ZSetOperations.TypedTuple<E>> reverseRangeByScoreWithScores(double min, double max)
      Description copied from interface: RedisZSet
      Get set of Tuples where score is between min and max from sorted set ordered from high to low.
      Specified by:
      reverseRangeByScoreWithScores in interface RedisZSet<E>
      Returns:
    • reverseRangeWithScores

      public Set<ZSetOperations.TypedTuple<E>> reverseRangeWithScores(long start, long end)
      Description copied from interface: RedisZSet
      Get set of Tuples in range from start to end from sorted set ordered from high to low.
      Specified by:
      reverseRangeWithScores in interface RedisZSet<E>
      Returns:
    • rangeAndStoreByLex

      public RedisZSet<E> rangeAndStoreByLex(String dstKey, org.springframework.data.domain.Range<String> range, Limit limit)
      Description copied from interface: RedisZSet
      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().
      Specified by:
      rangeAndStoreByLex in interface RedisZSet<E>
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      See Also:
    • reverseRangeAndStoreByLex

      public RedisZSet<E> reverseRangeAndStoreByLex(String dstKey, org.springframework.data.domain.Range<String> range, Limit limit)
      Description copied from interface: RedisZSet
      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().
      Specified by:
      reverseRangeAndStoreByLex in interface RedisZSet<E>
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      See Also:
    • rangeAndStoreByScore

      public RedisZSet<E> rangeAndStoreByScore(String dstKey, org.springframework.data.domain.Range<? extends Number> range, Limit limit)
      Description copied from interface: RedisZSet
      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().
      Specified by:
      rangeAndStoreByScore in interface RedisZSet<E>
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
      See Also:
    • reverseRangeAndStoreByScore

      public RedisZSet<E> reverseRangeAndStoreByScore(String dstKey, org.springframework.data.domain.Range<? extends Number> range, Limit limit)
      Description copied from interface: RedisZSet
      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().
      Specified by:
      reverseRangeAndStoreByScore in interface RedisZSet<E>
      Parameters:
      dstKey - must not be null.
      range - must not be null.
      limit - must not be null.
      Returns:
      a new RedisZSet pointing at destKey
    • remove

      public RedisZSet<E> remove(long start, long end)
      Description copied from interface: RedisZSet
      Remove elements in range between start and end from sorted set.
      Specified by:
      remove in interface RedisZSet<E>
      Returns:
      this set.
    • removeByLex

      public RedisZSet<E> removeByLex(org.springframework.data.domain.Range<String> range)
      Description copied from interface: RedisZSet
      Remove all elements in range.
      Specified by:
      removeByLex in interface RedisZSet<E>
      Parameters:
      range - must not be null.
      Returns:
      this set.
    • removeByScore

      public RedisZSet<E> removeByScore(double min, double max)
      Description copied from interface: RedisZSet
      Remove elements with scores between min and max from sorted set with the bound key.
      Specified by:
      removeByScore in interface RedisZSet<E>
      Returns:
      this set.
    • add

      public boolean add(E e)
      Description copied from interface: RedisZSet
      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 RedisZSet<E>
      Specified by:
      add in interface Set<E>
      Overrides:
      add in class AbstractCollection<E>
    • add

      public boolean add(E e, double score)
      Description copied from interface: RedisZSet
      Adds an element to the set with the given score, or updates the score if the element exists.
      Specified by:
      add in interface RedisZSet<E>
      Parameters:
      e - element to add
      score - element score
      Returns:
      true if a new element was added, false otherwise (only the score has been updated)
    • addIfAbsent

      public boolean addIfAbsent(E e, double score)
      Description copied from interface: RedisZSet
      Adds an element to the set with the given score if the element does not already exists.
      Specified by:
      addIfAbsent in interface RedisZSet<E>
      Parameters:
      e - element to add
      score - element score
      Returns:
      true if a new element was added, false otherwise (only the score has been updated)
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface Set<E>
      Overrides:
      clear in class AbstractCollection<E>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface Set<E>
      Overrides:
      contains in class AbstractCollection<E>
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface Set<E>
      Specified by:
      iterator in class AbstractCollection<E>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface Set<E>
      Overrides:
      remove in class AbstractCollection<E>
    • size

      public int size()
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface Set<E>
      Specified by:
      size in class AbstractCollection<E>
    • getDefaultScore

      public Double getDefaultScore()
      Description copied from interface: RedisZSet
      Returns the default score used by this set.
      Specified by:
      getDefaultScore in interface RedisZSet<E>
      Returns:
      the default score used by the implementation.
    • first

      public E first()
      Description copied from interface: RedisZSet
      Returns the first (lowest) element currently in this sorted set.
      Specified by:
      first in interface RedisZSet<E>
      Returns:
      the first (lowest) element currently in this sorted set.
    • popFirst

      public E popFirst()
      Description copied from interface: RedisZSet
      Removes the first (lowest) object at the top of this sorted set and returns that object as the value of this function.
      Specified by:
      popFirst in interface RedisZSet<E>
      Returns:
      the first (lowest) element currently in this sorted set.
    • popFirst

      public E popFirst(long timeout, TimeUnit unit)
      Description copied from interface: RedisZSet
      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.
      Specified by:
      popFirst in interface RedisZSet<E>
      unit - must not be null.
      Returns:
      the first (lowest) element currently in this sorted set.
    • last

      public E last()
      Description copied from interface: RedisZSet
      Returns the last (highest) element currently in this sorted set.
      Specified by:
      last in interface RedisZSet<E>
      Returns:
      the last (highest) element currently in this sorted set.
    • popLast

      public E popLast()
      Description copied from interface: RedisZSet
      Removes the last (highest) object at the top of this sorted set and returns that object as the value of this function.
      Specified by:
      popLast in interface RedisZSet<E>
      Returns:
      the last (highest) element currently in this sorted set.
    • popLast

      public E popLast(long timeout, TimeUnit unit)
      Description copied from interface: RedisZSet
      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.
      Specified by:
      popLast in interface RedisZSet<E>
      unit - must not be null.
      Returns:
      the last (highest) element currently in this sorted set.
    • rank

      public Long rank(Object o)
      Description copied from interface: RedisZSet
      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.
      Specified by:
      rank in interface RedisZSet<E>
      Parameters:
      o - object
      Returns:
      rank of the given object
    • reverseRank

      public Long reverseRank(Object o)
      Description copied from interface: RedisZSet
      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.
      Specified by:
      reverseRank in interface RedisZSet<E>
      Parameters:
      o - object
      Returns:
      reverse rank of the given object
    • lexCount

      public Long lexCount(org.springframework.data.domain.Range<String> range)
      Description copied from interface: RedisZSet
      Count number of elements within sorted set with value between Range#min and Range#max applying lexicographical ordering.
      Specified by:
      lexCount in interface RedisZSet<E>
      Parameters:
      range - must not be null.
      Returns:
      See Also:
    • score

      public Double score(Object o)
      Description copied from interface: RedisZSet
      Returns the score of the given element. Returns null if the element is not contained by the set.
      Specified by:
      score in interface RedisZSet<E>
      Parameters:
      o - object
      Returns:
      the score associated with the given object
    • getType

      public DataType getType()
      Description copied from interface: BoundKeyOperations
      Returns the associated Redis type.
      Specified by:
      getType in interface BoundKeyOperations<E>
      Returns:
      key type. null when used in pipeline / transaction.
    • scan

      public Cursor<E> scan()
      Specified by:
      scan in interface RedisZSet<E>
      Returns:
    • scan

      public Cursor<ZSetOperations.TypedTuple<E>> scan(ScanOptions options)
      Parameters:
      options -
      Returns:
      Since:
      1.4