Interface SortedSetCommands

All Known Subinterfaces:
JedisCommands
All Known Implementing Classes:
Jedis, JedisCluster, JedisPooled, JedisSentineled, JedisSharding, UnifiedJedis

public interface SortedSetCommands
  • Method Details

    • zadd

      long zadd(String key, double score, String member)
      Add the specified member having the specified score to the sorted set stored at key. If member is already a member of the sorted set the score is updated, and the element reinserted in the right position to ensure sorting. If key does not exist a new sorted set with the specified member as sole member is created. If the key exists but does not hold a sorted set value an error is returned.

      The score value can be the string representation of a double precision floating point number.

      Time complexity O(log(N)) with N being the number of elements in the sorted set

      Parameters:
      key -
      score -
      member -
      Returns:
      1 if the new element was added, 0 if the element was already a member of the sorted set and the score was updated
    • zadd

      long zadd(String key, double score, String member, ZAddParams params)
      Similar to ZADD but can be used with optional params.
      Parameters:
      key -
      score -
      member -
      params - ZAddParams
      Returns:
      1 if the new element was added, 0 if the element was already a member of the sorted set and the score was updated
      See Also:
    • zadd

      long zadd(String key, Map<String,Double> scoreMembers)
      Similar to ZADD but for multiple members.
      Parameters:
      key -
      scoreMembers -
      Returns:
      The number of elements added to the sorted set (excluding score updates).
      See Also:
    • zadd

      long zadd(String key, Map<String,Double> scoreMembers, ZAddParams params)
      Similar to ZADD but can be used with optional params, and fits for multiple members.
      Parameters:
      key -
      scoreMembers -
      params - ZAddParams
      Returns:
      The number of elements added to the sorted set (excluding score updates).
      See Also:
    • zaddIncr

      Double zaddIncr(String key, double score, String member, ZAddParams params)
      Increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.

      The score value should be the string representation of a numeric value, and accepts double precision floating point numbers. It is possible to provide a negative value to decrement the score.

      Time complexity O(log(N)) with N being the number of elements in the sorted set

      Parameters:
      key -
      score -
      member -
      params - ZAddParams
      Returns:
      1 if the new element was added, 0 if the element was already a member of the sorted set and the score was updated
    • zrem

      long zrem(String key, String... members)
      Remove the specified member from the sorted set value stored at key. If member was not a member of the set no operation is performed. If key does not hold a set value an error is returned.

      Time complexity O(log(N)) with N being the number of elements in the sorted set

      Parameters:
      key -
      members -
      Returns:
      1 if the new element was removed, 0 if the new element was not a member of the set
    • zincrby

      double zincrby(String key, double increment, String member)
      If member already exists in the sorted set adds the increment to its score and updates the position of the element in the sorted set accordingly. If member does not already exist in the sorted set it is added with increment as score (that is, like if the previous score was virtually zero). If key does not exist a new sorted set with the specified member as sole member is created. If the key exists but does not hold a sorted set value an error is returned.

      The score value can be the string representation of a double precision floating point number. It's possible to provide a negative value to perform a decrement.

      For an introduction to sorted sets check the Introduction to Redis data types page.

      Time complexity O(log(N)) with N being the number of elements in the sorted set

      Parameters:
      key -
      increment -
      member -
      Returns:
      The new score
    • zincrby

      Double zincrby(String key, double increment, String member, ZIncrByParams params)
      Similar to ZINCRBY but can be used with optionals params.
      Parameters:
      key -
      increment -
      member -
      params - ZIncrByParams
      Returns:
      The new score for key
      See Also:
    • zrank

      Long zrank(String key, String member)
      Return the rank (or index) of member in the sorted set at key, with scores being ordered from low to high.

      When the given member does not exist in the sorted set, the special value 'nil' is returned. The returned rank (or index) of the member is 0-based for both commands.

      Time complexity O(log(N))

      Parameters:
      key -
      member -
      Returns:
      The rank of the element as an integer reply if the element exists. A nil bulk reply if there is no such element
    • zrevrank

      Long zrevrank(String key, String member)
      Return the rank (or index) of member in the sorted set at key, with scores being ordered from high to low.

      When the given member does not exist in the sorted set, the special value 'nil' is returned. The returned rank (or index) of the member is 0-based for both commands.

      Time complexity O(log(N))

      Parameters:
      key -
      member -
      Returns:
      The rank of the element as an integer reply if the element exists. A nil bulk reply if there is no such element
    • zrankWithScore

      KeyValue<Long,Double> zrankWithScore(String key, String member)
      Returns the rank and the score of member in the sorted set stored at key, with the scores ordered from low to high.
      Parameters:
      key - the key
      member - the member
      Returns:
      the KeyValue contains rank and score.
    • zrevrankWithScore

      KeyValue<Long,Double> zrevrankWithScore(String key, String member)
      Returns the rank and the score of member in the sorted set stored at key, with the scores ordered from high to low.
      Parameters:
      key - the key
      member - the member
      Returns:
      the KeyValue contains rank and score.
    • zrange

      List<String> zrange(String key, long start, long stop)
      Returns the specified range of elements in the sorted set stored at key.

      Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.

      Parameters:
      key - the key to query
      start - the minimum index
      stop - the maximum index
      Returns:
      A List of Strings in the specified range
    • zrevrange

      List<String> zrevrange(String key, long start, long stop)
      Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.

      Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.

      Parameters:
      key - the key to query
      start - the minimum index
      stop - the maximum index
      Returns:
      A List of Strings in the specified range
    • zrangeWithScores

      List<Tuple> zrangeWithScores(String key, long start, long stop)
      Returns the specified range of elements in the sorted set stored at key with the scores.
      Parameters:
      key - the key to query
      start - the minimum index
      stop - the maximum index
      Returns:
      A List of Tuple in the specified range (elements names and their scores)
    • zrevrangeWithScores

      List<Tuple> zrevrangeWithScores(String key, long start, long stop)
      Similar to ZREVRANGE but the reply will include the scores of the returned elements.
      Parameters:
      key - the key to query
      start - the minimum index
      stop - the maximum index
      Returns:
      A List of Tuple in the specified range (elements names and their scores)
      See Also:
    • zrange

      List<String> zrange(String key, ZRangeParams zRangeParams)
      Similar to ZRANGE but can be used with additional params.
      Parameters:
      key - the key to query
      zRangeParams - ZRangeParams
      Returns:
      A List of Strings in the specified range
      See Also:
    • zrangeWithScores

      List<Tuple> zrangeWithScores(String key, ZRangeParams zRangeParams)
      Similar to ZRANGE but can be used with additional params.
      Parameters:
      key - the key to query
      zRangeParams - ZRangeParams
      Returns:
      A List of Tuple in the specified range (elements names and their scores)
      See Also:
    • zrangestore

      long zrangestore(String dest, String src, ZRangeParams zRangeParams)
      Similar to ZRANGE but stores the result in dest.
      Parameters:
      dest - the storing key
      src - the key to query
      zRangeParams - ZRangeParams
      Returns:
      The number of elements in the resulting sorted set
      See Also:
    • zrandmember

      String zrandmember(String key)
      Return a random element from the sorted set value stored at key.

      Time complexity O(N) where N is the number of elements returned

      Parameters:
      key -
      Returns:
      Random String from the set
    • zrandmember

      List<String> zrandmember(String key, long count)
      Return an array of distinct elements. The array's length is either count or the sorted set's cardinality (ZCARD), whichever is lower.

      Time complexity O(N) where N is the number of elements returned

      Parameters:
      key -
      count - choose up to count elements
      Returns:
      A list of distinct Strings from the set
    • zrandmemberWithScores

      List<Tuple> zrandmemberWithScores(String key, long count)
      Similar to ZRANDMEMBER but the replay will include the scores with the result.
      Parameters:
      key -
      count - choose up to count elements
      Returns:
      A List of distinct Strings with their scores
      See Also:
    • zcard

      long zcard(String key)
      Return the sorted set cardinality (number of elements). If the key does not exist 0 is returned, like for empty sorted sets.

      Time complexity O(1)

      Parameters:
      key -
      Returns:
      The cardinality (number of elements) of the set as an integer
    • zscore

      Double zscore(String key, String member)
      Return the score of the specified element of the sorted set at key. If the specified element does not exist in the sorted set, or the key does not exist at all, a special 'nil' value is returned.

      Time complexity O(1)

      Parameters:
      key -
      member -
      Returns:
      The score
    • zmscore

      List<Double> zmscore(String key, String... members)
      Return the scores associated with the specified members in the sorted set stored at key. For every member that does not exist in the sorted set, a nil value is returned.

      Time complexity O(N) where N is the number of members being requested

      Parameters:
      key -
      members -
      Returns:
      The scores
    • zpopmax

      Tuple zpopmax(String key)
      Remove and return the member with the highest score in the sorted set stored at key.

      Time complexity O(log(N)) with N being the number of elements in the sorted set

      Parameters:
      key -
      Returns:
      The popped element and the score
    • zpopmax

      List<Tuple> zpopmax(String key, int count)
      Remove and return up to count members with the highest scores in the sorted set stored at key.

      Time complexity O(log(N)*M) with N being the number of elements in the sorted set, and M being the number of elements popped.

      Parameters:
      key -
      count - the number of elements to pop
      Returns:
      A List of popped elements and scores
    • zpopmin

      Tuple zpopmin(String key)
      Remove and return the member with the lowest score in the sorted set stored at key.

      Time complexity O(log(N)) with N being the number of elements in the sorted set

      Parameters:
      key -
      Returns:
      The popped element and the score
    • zpopmin

      List<Tuple> zpopmin(String key, int count)
      Remove and return up to count members with the lowest scores in the sorted set stored at key.

      Time complexity O(log(N)*M) with N being the number of elements in the sorted set, and M being the number of elements popped.

      Parameters:
      key -
      count - the number of elements to pop
      Returns:
      A List of popped elements and scores
    • zcount

      long zcount(String key, double min, double max)
      Return the number of elements in the sorted set at key with a score between min and max.

      Time complexity O(log(N)) with N being the number of elements in the sorted set.

      Parameters:
      key - the key to query
      min - minimum score
      max - maximum score
      Returns:
      The number of elements in the specified score range.
    • zcount

      long zcount(String key, String min, String max)
      Similar to ZCOUNT but with exclusive range.
      See Also:
    • zrangeByScore

      List<String> zrangeByScore(String key, double min, double max)
      Return all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max). The elements are considered to be ordered from low to high scores.

      Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned.

      Parameters:
      key - the key to query
      min - minimum score
      max - maximum score
      Returns:
      A List of elements in the specified score range
    • zrangeByScore

      List<String> zrangeByScore(String key, String min, String max)
      Similar to ZRANGE but with exclusive range.
      See Also:
    • zrevrangeByScore

      List<String> zrevrangeByScore(String key, double max, double min)
      Return all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores.

      The elements having the same score are returned in reverse lexicographical order.

      Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned.

      Parameters:
      key - the key to query
      max - maximum score
      min - minimum score
      Returns:
      A List of elements in the specified score range
    • zrangeByScore

      List<String> zrangeByScore(String key, double min, double max, int offset, int count)
      Similar to ZRANGE but with exclusive range.
      Parameters:
      key - the key to query
      min - minimum score
      max - maximum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrevrangeByScore

      List<String> zrevrangeByScore(String key, String max, String min)
      Similar to ZREVRANGE but with exclusive range.
      See Also:
    • zrangeByScore

      List<String> zrangeByScore(String key, String min, String max, int offset, int count)
      Similar to ZRANGE but with limit option,
      Parameters:
      key - the key to query
      min - minimum score
      max - maximum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrevrangeByScore

      List<String> zrevrangeByScore(String key, double max, double min, int offset, int count)
      Similar to ZRANGE but with limit option,
      Parameters:
      key - the key to query
      max - maximum score
      min - minimum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrangeByScoreWithScores

      List<Tuple> zrangeByScoreWithScores(String key, double min, double max)
      Similar to ZRANGE but return with scores.
      Parameters:
      key - the key to query
      min - minimum score
      max - maximum score
      Returns:
      A List of elements with scores in the specified score range
      See Also:
    • zrevrangeByScoreWithScores

      List<Tuple> zrevrangeByScoreWithScores(String key, double max, double min)
      Similar to ZREVRANGE but return with scores.
      Parameters:
      key - the key to query
      max - maximum score
      min - minimum score
      Returns:
      A List of elements with scores in the specified score range
      See Also:
    • zrangeByScoreWithScores

      List<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count)
      Similar to ZRANGE but with limit option, and return with scores.
      Parameters:
      key - the key to query
      min - minimum score
      max - maximum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrevrangeByScore

      List<String> zrevrangeByScore(String key, String max, String min, int offset, int count)
      Similar to ZREVRANGE but with limit option,
      Parameters:
      key - the key to query
      max - maximum score
      min - minimum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrangeByScoreWithScores

      List<Tuple> zrangeByScoreWithScores(String key, String min, String max)
      Similar to ZRANGE but with exclusive range, and return with scores.
      See Also:
    • zrevrangeByScoreWithScores

      List<Tuple> zrevrangeByScoreWithScores(String key, String max, String min)
      Similar to ZREVRANGE but with exclusive range, and return with scores.
      See Also:
    • zrangeByScoreWithScores

      List<Tuple> zrangeByScoreWithScores(String key, String min, String max, int offset, int count)
      Similar to ZRANGE but with exclusive range, with limit options and return with scores.
      Parameters:
      key - the key to query
      min - minimum score
      max - maximum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrevrangeByScoreWithScores

      List<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count)
      Similar to ZREVRANGE but with limit options and return with scores.
      Parameters:
      key - the key to query
      max - maximum score
      min - minimum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrevrangeByScoreWithScores

      List<Tuple> zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count)
      Similar to ZREVRANGE but with exclusive range, with limit options and return with scores.
      Parameters:
      key - the key to query
      max - maximum score
      min - minimum score
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zremrangeByRank

      long zremrangeByRank(String key, long start, long stop)
      Remove all elements in the sorted set at key with rank between start and end. Start and end are 0-based with rank 0 being the element with the lowest score. Both start and end can be negative numbers, where they indicate offsets starting at the element with the highest rank. For example: -1 is the element with the highest score, -2 the element with the second highest score and so forth.

      Time complexity O(log(N))+O(M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.

      Parameters:
      key -
      start -
      stop -
      Returns:
      The number of elements removed
    • zremrangeByScore

      long zremrangeByScore(String key, double min, double max)
      Remove all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max).

      Time complexity O(log(N))+O(M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.

      Parameters:
      key -
      min - minimum score to remove
      max - maximum score to remove
      Returns:
      The number of elements removed
    • zremrangeByScore

      long zremrangeByScore(String key, String min, String max)
      Similar to ZREMRANGE but with limit option.
      See Also:
    • zlexcount

      long zlexcount(String key, String min, String max)
      Return the number of elements in the sorted set at key with a value between min and max, when all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering.

      Time complexity O(log(N)) with N being the number of elements in the sorted set.

      Parameters:
      key -
      min - minimum value
      max - maximum value
      Returns:
      The number of elements in the specified score range
    • zrangeByLex

      List<String> zrangeByLex(String key, String min, String max)
      Return all the elements in the sorted set at key with a value between min and max, when all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering.

      Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned.

      Parameters:
      key -
      min - minimum value
      max - maximum value
      Returns:
      A List of elements in the specified score range
    • zrangeByLex

      List<String> zrangeByLex(String key, String min, String max, int offset, int count)
      Similar to ZRANGE but with limit option.
      Parameters:
      key -
      min - minimum value
      max - maximum value
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zrevrangeByLex

      List<String> zrevrangeByLex(String key, String max, String min)
      Return all the elements in the sorted set at key with a value between max and min, when all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering.

      Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned.

      Parameters:
      key -
      max - maximum value
      min - minimum value
      Returns:
      A List of elements in the specified score range
    • zrevrangeByLex

      List<String> zrevrangeByLex(String key, String max, String min, int offset, int count)
      Similar to ZRANGE but with limit option.
      Parameters:
      key -
      max - maximum value
      min - minimum value
      offset - the first index of the sub-range
      count - count of the sub-range. A negative count returns all elements from the offset
      Returns:
      A List of elements in the specified score range
      See Also:
    • zremrangeByLex

      long zremrangeByLex(String key, String min, String max)
      Remove all elements in the sorted set stored at key between the lexicographical range specified by min and max, when all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering.

      Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.

      Parameters:
      key -
      min - minimum value to remove
      max - maximum value to remove
      Returns:
      The number of elements removed
    • zscan

      default ScanResult<Tuple> zscan(String key, String cursor)
    • zscan

      ScanResult<Tuple> zscan(String key, String cursor, ScanParams params)
    • bzpopmax

      KeyedZSetElement bzpopmax(double timeout, String... keys)
      The blocking version of ZPOPMAX
      Parameters:
      timeout - specifying the maximum number of seconds to block. A timeout of zero can be used to block indefinitely.
      keys -
    • bzpopmin

      KeyedZSetElement bzpopmin(double timeout, String... keys)
      The blocking version of ZPOPMIN
      Parameters:
      timeout - specifying the maximum number of seconds to block. A timeout of zero can be used to block indefinitely.
      keys -
    • zdiff

      Set<String> zdiff(String... keys)
      Compute the difference between all the sets in the given keys.

      Time complexity O(L + (N-K)log(N)) worst case where L is the total number of elements in all the sets, N is the size of the first set, and K is the size of the result set.

      Parameters:
      keys - group of sets
      Returns:
      The result of the difference
    • zdiffWithScores

      Set<Tuple> zdiffWithScores(String... keys)
      Compute the difference between all the sets in the given keys. Return the result with scores.
      Parameters:
      keys - group of sets
      Returns:
      The result of the difference with their scores
    • zdiffStore

      long zdiffStore(String dstkey, String... keys)
      Compute the difference between all the sets in the given keys. Store the result in dstkey.
      Parameters:
      dstkey -
      keys - group of sets
      Returns:
      The number of elements in the resulting sorted set at dstkey.
    • zinter

      Set<String> zinter(ZParams params, String... keys)
      Compute the intersection between all the sets in the given keys.

      Time complexity O(N*K)+O(M*log(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.

      Parameters:
      params - ZParams
      keys - group of sets
      Returns:
      The result of the intersection
    • zinterWithScores

      Set<Tuple> zinterWithScores(ZParams params, String... keys)
      Compute the intersection between all the sets in the given keys. Return the result with scores.
      Parameters:
      params - ZParams
      keys - group of sets
      Returns:
      The result of the intersection with their scores
    • zinterstore

      long zinterstore(String dstkey, String... sets)
      Compute the intersection between all the sets in the given keys. Store the result in dstkey.
      Parameters:
      dstkey -
      sets - group of sets
      Returns:
      The number of elements in the resulting sorted set at dstkey
    • zinterstore

      long zinterstore(String dstkey, ZParams params, String... sets)
      Compute the intersection between all the sets in the given keys. Store the result in dstkey.
      Parameters:
      dstkey -
      params - ZParams
      sets - group of sets
      Returns:
      The number of elements in the resulting sorted set at dstkey
    • zintercard

      long zintercard(String... keys)
      Similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.

      Time complexity O(N*K) worst case with N being the smallest input sorted set, K being the number of input sorted sets

      Parameters:
      keys - group of sets
      Returns:
      The number of elements in the resulting intersection
      See Also:
    • zintercard

      long zintercard(long limit, String... keys)
      Similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.

      Time complexity O(N*K) worst case with N being the smallest input sorted set, K being the number of input sorted sets

      Parameters:
      limit - If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and yield limit as the cardinality
      keys - group of sets
      Returns:
      The number of elements in the resulting intersection
      See Also:
    • zunion

      Set<String> zunion(ZParams params, String... keys)
      Compute the union between all the sets in the given keys.

      Time complexity O(N)+O(M log(M)) with N being the sum of the sizes of the input sorted sets, and M being the number of elements in the resulting sorted set.

      Parameters:
      params - ZParams
      keys - group of sets
      Returns:
      The result of the union
    • zunionWithScores

      Set<Tuple> zunionWithScores(ZParams params, String... keys)
      Compute the union between all the sets in the given keys. Return the result with scores.
      Parameters:
      params - ZParams
      keys - group of sets
      Returns:
      The result of the union with their scores
    • zunionstore

      long zunionstore(String dstkey, String... sets)
      Compute the union between all the sets in the given keys. Store the result in dstkey.
      Parameters:
      dstkey -
      sets - group of sets
      Returns:
      The number of elements in the resulting sorted set at dstkey
    • zunionstore

      long zunionstore(String dstkey, ZParams params, String... sets)
      Compute the union between all the sets in the given keys. Store the result in dstkey.
      Parameters:
      dstkey -
      params - ZParams
      sets - group of sets
      Returns:
      The number of elements in the resulting sorted set at dstkey
    • zmpop

      KeyValue<String,List<Tuple>> zmpop(SortedSetOption option, String... keys)
    • zmpop

      KeyValue<String,List<Tuple>> zmpop(SortedSetOption option, int count, String... keys)
    • bzmpop

      KeyValue<String,List<Tuple>> bzmpop(long timeout, SortedSetOption option, String... keys)
    • bzmpop

      KeyValue<String,List<Tuple>> bzmpop(long timeout, SortedSetOption option, int count, String... keys)