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
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 Summary
Modifier and TypeMethodDescriptionbooleanAdds an element to the set with a default score.booleanAdds an element to the set with the given score, or updates the score if the element exists.default booleanaddIfAbsent(E e) Adds an element to the set using thedefault scoreif the element does not already exists.booleanaddIfAbsent(E e, double score) Adds an element to the set with the given score if the element does not already exists.static <E> RedisZSet<E>create(String key, RedisOperations<String, E> operations) Constructs a newRedisZSetinstance with a default score of 1.static <E> RedisZSet<E>create(String key, RedisOperations<String, E> operations, double defaultScore) Constructs a newRedisZSetinstance.diff(Collection<? extends RedisZSet<?>> sets) Diff this set and otherRedisZSets.Diff this set and anotherRedisZSet.diffAndStore(Collection<? extends RedisZSet<?>> sets, String destKey) diffAndStore(RedisZSet<?> set, String destKey) diffWithScores(Collection<? extends RedisZSet<?>> sets) Diff this set and otherRedisZSets.diffWithScores(RedisZSet<?> set) Diff this set and anotherRedisZSet.first()Returns the first (lowest) element currently in this sorted set.Returns the default score used by this set.intersect(Collection<? extends RedisZSet<?>> sets) Intersect this set and otherRedisZSets.Intersect this set and anotherRedisZSet.intersectAndStore(Collection<? extends RedisZSet<?>> sets, String destKey) intersectAndStore(RedisZSet<?> set, String destKey) intersectWithScores(Collection<? extends RedisZSet<?>> sets) Intersect this set and otherRedisZSets.intersectWithScores(RedisZSet<?> set) Intersect this set and anotherRedisZSet.last()Returns the last (highest) element currently in this sorted set.Count number of elements within sorted set with value betweenRange#minandRange#maxapplying lexicographical ordering.popFirst()Removes the first (lowest) object at the top of this sorted set and returns that object as the value of this function.Removes the first (lowest) object at the top of this sorted set and returns that object as the value of this function.popLast()Removes the last (highest) object at the top of this sorted set and returns that object as the value of this function.Removes the last (highest) object at the top of this sorted set and returns that object as the value of this function.Get random element from the set.range(long start, long end) Get elements betweenstartandendfrom sorted set.rangeAndStoreByLex(String dstKey, Range<String> range) Store all elements atdstKeywith lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().rangeAndStoreByLex(String dstKey, Range<String> range, Limit limit) Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().rangeAndStoreByScore(String dstKey, Range<? extends Number> range) Store all elements atdstKeywith ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().rangeAndStoreByScore(String dstKey, Range<? extends Number> range, Limit limit) Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().rangeByLex(Range<String> range) Get all elements with lexicographical ordering with a value betweenRange.getLowerBound()andRange.getUpperBound().rangeByLex(Range<String> range, Limit limit) Get all elements n elements, where n =Limit.getCount(), starting atLimit.getOffset()with lexicographical ordering having a value betweenRange.getLowerBound()andRange.getUpperBound().Deprecated, for removal: This API element is subject to removal in a future version.since 3.0.rangeByLex(RedisZSetCommands.Range range, Limit limit) Deprecated, for removal: This API element is subject to removal in a future version.since 3.0.rangeByScore(double min, double max) Get elements where score is betweenminandmaxfrom sorted set.rangeByScoreWithScores(double min, double max) rangeWithScores(long start, long end) Returns the rank (position) of the given element in the set, in ascending order.remove(long start, long end) Remove elements in range betweenstartandendfrom sorted set.removeByLex(Range<String> range) Remove all elements in range.removeByScore(double min, double max) Remove elements with scores betweenminandmaxfrom sorted set with the bound key.reverseRange(long start, long end) Get elements in range fromstarttoendfrom sorted set ordered from high to low.reverseRangeAndStoreByLex(String dstKey, Range<String> range) Store all elements atdstKeywith reverse lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().reverseRangeAndStoreByLex(String dstKey, Range<String> range, Limit limit) Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with reverse lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().reverseRangeAndStoreByScore(String dstKey, Range<? extends Number> range) Store all elements atdstKeywith reverse ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().reverseRangeAndStoreByScore(String dstKey, Range<? extends Number> range, Limit limit) Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with reverse ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().reverseRangeByLex(Range<String> range) Get all elements with reverse lexicographical ordering with a value betweenRange.getLowerBound()andRange.getUpperBound().reverseRangeByLex(Range<String> range, Limit limit) Get all elements n elements, where n =Limit.getCount(), starting atLimit.getOffset()with reverse lexicographical ordering having a value betweenRange.getLowerBound()andRange.getUpperBound().Deprecated, for removal: This API element is subject to removal in a future version.since 3.0.reverseRangeByLex(RedisZSetCommands.Range range, Limit limit) Deprecated, for removal: This API element is subject to removal in a future version.since 3.0.reverseRangeByScore(double min, double max) Get elements where score is betweenminandmaxfrom sorted set ordered from high to low.reverseRangeByScoreWithScores(double min, double max) reverseRangeWithScores(long start, long end) Returns the rank (position) of the given element in the set, in descending order.scan()Returns the score of the given element.union(Collection<? extends RedisZSet<?>> sets) Union this set and otherRedisZSets.Union this set and anotherRedisZSet.unionAndStore(Collection<? extends RedisZSet<?>> sets, String destKey) unionAndStore(RedisZSet<?> set, String destKey) unionWithScores(Collection<? extends RedisZSet<?>> sets) Union this set and otherRedisZSets.unionWithScores(RedisZSet<?> set) Union this set and anotherRedisZSet.Methods inherited from interface org.springframework.data.redis.core.BoundKeyOperations
expiration, expire, expire, expireAt, expireAt, getExpire, getKey, getType, persist, renameMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface org.springframework.data.redis.support.collections.RedisStore
getOperations
-
Method Details
-
create
Constructs a newRedisZSetinstance with a default score of 1.- Parameters:
key- Redis key of this set.operations-RedisOperationsfor 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 newRedisZSetinstance.- Parameters:
key- Redis key of this set.operations-RedisOperationsfor the value type of this set.defaultScore-- Since:
- 2.6
-
diff
Diff this set and anotherRedisZSet.- Parameters:
set- must not be null.- Returns:
- a
Setcontaining the values that differ. - Since:
- 2.6
-
diff
Diff this set and otherRedisZSets.- Parameters:
sets- must not be null.- Returns:
- a
Setcontaining the values that differ. - Since:
- 2.6
-
diffWithScores
Diff this set and anotherRedisZSet.- Parameters:
set- must not be null.- Returns:
- a
Setcontaining the values that differ with their scores. - Since:
- 2.6
-
diffWithScores
Diff this set and otherRedisZSets.- Parameters:
sets- must not be null.- Returns:
- a
Setcontaining the values that differ with their scores. - Since:
- 2.6
-
diffAndStore
Create a newRedisZSetby diffing this sorted set andRedisZSetand store result in destinationdestKey.- Parameters:
set- must not be null.destKey- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey. - Since:
- 2.6
-
diffAndStore
Create a newRedisZSetby diffing this sorted set and the collectionRedisZSetand store result in destinationdestKey.- Parameters:
sets- must not be null.destKey- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey. - Since:
- 2.6
-
intersect
Intersect this set and anotherRedisZSet.- Parameters:
set- must not be null.- Returns:
- a
Setcontaining the intersecting values. - Since:
- 2.6
-
intersect
Intersect this set and otherRedisZSets.- Parameters:
sets- must not be null.- Returns:
- a
Setcontaining the intersecting values. - Since:
- 2.6
-
intersectWithScores
Intersect this set and anotherRedisZSet.- Parameters:
set- must not be null.- Returns:
- a
Setcontaining the intersecting values with their scores. - Since:
- 2.6
-
intersectWithScores
Intersect this set and otherRedisZSets.- Parameters:
sets- must not be null.- Returns:
- a
Setcontaining the intersecting values with their scores. - Since:
- 2.6
-
intersectAndStore
Create a newRedisZSetby intersecting this sorted set andRedisZSetand store result in destinationdestKey.- Parameters:
set- must not be null.destKey- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey
-
intersectAndStore
Create a newRedisZSetby intersecting this sorted set and the collectionRedisZSetand store result in destinationdestKey.- Parameters:
sets- must not be null.destKey- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey
-
union
Union this set and anotherRedisZSet.- Parameters:
set- must not be null.- Returns:
- a
Setcontaining the combined values. - Since:
- 2.6
-
union
Union this set and otherRedisZSets.- Parameters:
sets- must not be null.- Returns:
- a
Setcontaining the combined values. - Since:
- 2.6
-
unionWithScores
Union this set and anotherRedisZSet.- Parameters:
set- must not be null.- Returns:
- a
Setcontaining the combined values with their scores. - Since:
- 2.6
-
unionWithScores
Union this set and otherRedisZSets.- Parameters:
sets- must not be null.- Returns:
- a
Setcontaining the combined values with their scores. - Since:
- 2.6
-
unionAndStore
Create a newRedisZSetby union this sorted set andRedisZSetand store result in destinationdestKey.- Parameters:
set- must not be null.destKey- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey
-
unionAndStore
Create a newRedisZSetby union this sorted set and the collectionRedisZSetand store result in destinationdestKey.- Parameters:
sets- must not be null.destKey- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey
-
randomValue
E randomValue()Get random element from the set.- Returns:
- Since:
- 2.6
-
range
Get elements betweenstartandendfrom sorted set.- Parameters:
start-end-- Returns:
-
reverseRange
Get elements in range fromstarttoendfrom sorted set ordered from high to low.- Parameters:
start-end-- Returns:
-
rangeByLex
Deprecated, for removal: This API element is subject to removal in a future version.since 3.0. Please userangeByLex(Range)instead.Get all elements with lexicographical ordering with a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
range- must not be null.- Returns:
- Since:
- 1.7
- See Also:
-
rangeByLex
Get all elements with lexicographical ordering with a value betweenRange.getLowerBound()andRange.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 userangeByLex(Range, Limit)instead.Get all elements n elements, where n =Limit.getCount(), starting atLimit.getOffset()with lexicographical ordering having a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
range- must not be null.limit- can be null.- Returns:
- Since:
- 1.7
- See Also:
-
rangeByLex
Get all elements n elements, where n =Limit.getCount(), starting atLimit.getOffset()with lexicographical ordering having a value betweenRange.getLowerBound()andRange.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 usereverseRangeByLex(Range, Limit)instead.Get all elements with reverse lexicographical ordering with a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
range- must not be null.- Returns:
- Since:
- 2.4
- See Also:
-
reverseRangeByLex
Get all elements with reverse lexicographical ordering with a value betweenRange.getLowerBound()andRange.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 usereverseRangeByLex(Range, Limit)instead.Get all elements n elements, where n =Limit.getCount(), starting atLimit.getOffset()with reverse lexicographical ordering having a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
range- must not be null.limit- can be null.- Returns:
- Since:
- 2.4
- See Also:
-
reverseRangeByLex
Get all elements n elements, where n =Limit.getCount(), starting atLimit.getOffset()with reverse lexicographical ordering having a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
range- must not be null.limit- can be null.- Returns:
- Since:
- 3.0
- See Also:
-
rangeByScore
Get elements where score is betweenminandmaxfrom sorted set.- Parameters:
min-max-- Returns:
-
reverseRangeByScore
Get elements where score is betweenminandmaxfrom sorted set ordered from high to low.- Parameters:
min-max-- Returns:
-
rangeWithScores
- Parameters:
start-end-- Returns:
-
reverseRangeWithScores
- Parameters:
start-end-- Returns:
-
rangeByScoreWithScores
- Parameters:
min-max-- Returns:
-
reverseRangeByScoreWithScores
- Parameters:
min-max-- Returns:
-
rangeAndStoreByLex
Store all elements atdstKeywith lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
- See Also:
-
rangeAndStoreByLex
Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.limit- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
- See Also:
-
reverseRangeAndStoreByLex
Store all elements atdstKeywith reverse lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
- See Also:
-
reverseRangeAndStoreByLex
Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with reverse lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.limit- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
- See Also:
-
rangeAndStoreByScore
Store all elements atdstKeywith ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
- See Also:
-
rangeAndStoreByScore
Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.limit- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
- See Also:
-
reverseRangeAndStoreByScore
Store all elements atdstKeywith reverse ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
- See Also:
-
reverseRangeAndStoreByScore
Store n elements atdstKey, where n =Limit.getCount(), starting atLimit.getOffset()with reverse ordering by score from ZSET at the bound key with a score betweenRange.getLowerBound()andRange.getUpperBound().- Parameters:
dstKey- must not be null.range- must not be null.limit- must not be null.- Returns:
- a new
RedisZSetpointing atdestKey - Since:
- 3.0
-
remove
Remove elements in range betweenstartandendfrom sorted set.- Parameters:
start-end-- Returns:
thisset.
-
removeByLex
Remove all elements in range.- Parameters:
range- must not be null.- Returns:
thisset.- Since:
- 2.5
-
removeByScore
Remove elements with scores betweenminandmaxfrom sorted set with the bound key.- Parameters:
min-max-- Returns:
thisset.
-
add
Adds an element to the set with the given score, or updates the score if the element exists.- Parameters:
e- element to addscore- element score- Returns:
- true if a new element was added, false otherwise (only the score has been updated)
-
add
Adds an element to the set with a default score. Equivalent toadd(e, getDefaultScore()). The score value is implementation specific. -
addIfAbsent
Adds an element to the set using thedefault scoreif 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
Adds an element to the set with the given score if the element does not already exists.- Parameters:
e- element to addscore- element score- Returns:
- true if a new element was added, false otherwise (only the score has been updated)
- Since:
- 2.5
-
lexCount
Count number of elements within sorted set with value betweenRange#minandRange#maxapplying lexicographical ordering.- Parameters:
range- must not be null.- Returns:
- Since:
- 2.4
- See Also:
-
score
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
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
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
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 ortimeoutreached.- 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
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 ortimeoutreached.- 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
- Returns:
- Since:
- 1.4
-