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 TypeMethodDescriptionboolean
Adds an element to the set with a default score.boolean
Adds an element to the set with the given score, or updates the score if the element exists.default boolean
addIfAbsent
(E e) Adds an element to the set using thedefault score
if the element does not already exists.boolean
addIfAbsent
(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 newRedisZSet
instance with a default score of 1.static <E> RedisZSet<E>
create
(String key, RedisOperations<String, E> operations, double defaultScore) Constructs a newRedisZSet
instance.diff
(Collection<? extends RedisZSet<?>> sets) Diff this set and otherRedisZSet
s.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 otherRedisZSet
s.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 otherRedisZSet
s.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 otherRedisZSet
s.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#min
andRange#max
applying 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 betweenstart
andend
from sorted set.rangeAndStoreByLex
(String dstKey, Range<String> range) Store all elements atdstKey
with 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 atdstKey
with 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 betweenmin
andmax
from 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 betweenstart
andend
from sorted set.removeByLex
(Range<String> range) Remove all elements in range.removeByScore
(double min, double max) Remove elements with scores betweenmin
andmax
from sorted set with the bound key.reverseRange
(long start, long end) Get elements in range fromstart
toend
from sorted set ordered from high to low.reverseRangeAndStoreByLex
(String dstKey, Range<String> range) Store all elements atdstKey
with 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 atdstKey
with 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 betweenmin
andmax
from 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 otherRedisZSet
s.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 otherRedisZSet
s.unionWithScores
(RedisZSet<?> set) Union this set and anotherRedisZSet
.Methods inherited from interface org.springframework.data.redis.core.BoundKeyOperations
expire, expire, expireAt, expireAt, getExpire, getKey, getType, persist, rename
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface org.springframework.data.redis.support.collections.RedisStore
getOperations
-
Method Details
-
create
Constructs a newRedisZSet
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 newRedisZSet
instance.- Parameters:
key
- Redis key of this set.operations
-RedisOperations
for the value type of this set.defaultScore
-- Since:
- 2.6
-
diff
Diff this set and anotherRedisZSet
.- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the values that differ. - Since:
- 2.6
-
diff
Diff this set and otherRedisZSet
s.- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the values that differ. - Since:
- 2.6
-
diffWithScores
Diff this set and anotherRedisZSet
.- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the values that differ with their scores. - Since:
- 2.6
-
diffWithScores
Diff this set and otherRedisZSet
s.- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the values that differ with their scores. - Since:
- 2.6
-
diffAndStore
Create a newRedisZSet
by diffing this sorted set andRedisZSet
and store result in destinationdestKey
.- Parameters:
set
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
. - Since:
- 2.6
-
diffAndStore
Create a newRedisZSet
by diffing this sorted set and the collectionRedisZSet
and store result in destinationdestKey
.- Parameters:
sets
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
. - Since:
- 2.6
-
intersect
Intersect this set and anotherRedisZSet
.- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the intersecting values. - Since:
- 2.6
-
intersect
Intersect this set and otherRedisZSet
s.- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the intersecting values. - Since:
- 2.6
-
intersectWithScores
Intersect this set and anotherRedisZSet
.- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the intersecting values with their scores. - Since:
- 2.6
-
intersectWithScores
Intersect this set and otherRedisZSet
s.- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the intersecting values with their scores. - Since:
- 2.6
-
intersectAndStore
Create a newRedisZSet
by intersecting this sorted set andRedisZSet
and store result in destinationdestKey
.- Parameters:
set
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
intersectAndStore
Create a newRedisZSet
by intersecting this sorted set and the collectionRedisZSet
and store result in destinationdestKey
.- Parameters:
sets
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
union
Union this set and anotherRedisZSet
.- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the combined values. - Since:
- 2.6
-
union
Union this set and otherRedisZSet
s.- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the combined values. - Since:
- 2.6
-
unionWithScores
Union this set and anotherRedisZSet
.- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the combined values with their scores. - Since:
- 2.6
-
unionWithScores
Union this set and otherRedisZSet
s.- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the combined values with their scores. - Since:
- 2.6
-
unionAndStore
Create a newRedisZSet
by union this sorted set andRedisZSet
and store result in destinationdestKey
.- Parameters:
set
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
unionAndStore
Create a newRedisZSet
by union this sorted set and the collectionRedisZSet
and store result in destinationdestKey
.- Parameters:
sets
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
randomValue
E randomValue()Get random element from the set.- Returns:
- Since:
- 2.6
-
range
Get elements betweenstart
andend
from sorted set.- Parameters:
start
-end
-- Returns:
-
reverseRange
Get elements in range fromstart
toend
from 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 betweenmin
andmax
from sorted set.- Parameters:
min
-max
-- Returns:
-
reverseRangeByScore
Get elements where score is betweenmin
andmax
from 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 atdstKey
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.- Returns:
- a new
RedisZSet
pointing 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
RedisZSet
pointing atdestKey
- Since:
- 3.0
- See Also:
-
reverseRangeAndStoreByLex
Store all elements atdstKey
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.- Returns:
- a new
RedisZSet
pointing 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
RedisZSet
pointing atdestKey
- Since:
- 3.0
- See Also:
-
rangeAndStoreByScore
Store all elements atdstKey
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.- Returns:
- a new
RedisZSet
pointing 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
RedisZSet
pointing atdestKey
- Since:
- 3.0
- See Also:
-
reverseRangeAndStoreByScore
Store all elements atdstKey
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.- Returns:
- a new
RedisZSet
pointing 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
RedisZSet
pointing atdestKey
- Since:
- 3.0
-
remove
Remove elements in range betweenstart
andend
from sorted set.- Parameters:
start
-end
-- Returns:
this
set.
-
removeByLex
Remove all elements in range.- Parameters:
range
- must not be null.- Returns:
this
set.- Since:
- 2.5
-
removeByScore
Remove elements with scores betweenmin
andmax
from sorted set with the bound key.- Parameters:
min
-max
-- Returns:
this
set.
-
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 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
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#min
andRange#max
applying 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 ortimeout
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
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 ortimeout
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
- Returns:
- Since:
- 1.4
-