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>
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
-
Field Summary
Fields inherited from class org.springframework.data.redis.support.collections.AbstractRedisCollection
ENCODING
-
Constructor Summary
ConstructorDescriptionDefaultRedisZSet
(String key, RedisOperations<String, E> operations) Constructs a newDefaultRedisZSet
instance with a default score of 1.DefaultRedisZSet
(String key, RedisOperations<String, E> operations, double defaultScore) Constructs a newDefaultRedisZSet
instance.DefaultRedisZSet
(BoundZSetOperations<String, E> boundOps) Constructs a newDefaultRedisZSet
instance with a default score of '1'.DefaultRedisZSet
(BoundZSetOperations<String, E> boundOps, double defaultScore) Constructs a newDefaultRedisZSet
instance. -
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.boolean
addIfAbsent
(E e, double score) Adds an element to the set with the given score if the element does not already exists.void
clear()
boolean
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.getType()
Returns the associated Redis type.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
.iterator()
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, org.springframework.data.domain.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, org.springframework.data.domain.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
(org.springframework.data.domain.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()
.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.boolean
removeByLex
(org.springframework.data.domain.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, org.springframework.data.domain.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, org.springframework.data.domain.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
(org.springframework.data.domain.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()
.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()
scan
(ScanOptions options) Returns the score of the given element.int
size()
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 class org.springframework.data.redis.support.collections.AbstractRedisCollection
addAll, checkResult, containsAll, equals, expire, expireAt, getExpire, getKey, getOperations, hashCode, persist, removeAll, rename, toString
Methods inherited from class java.util.AbstractCollection
isEmpty, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.data.redis.core.BoundKeyOperations
expire, expire, expireAt, expireAt, getExpire, getKey, 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
Methods inherited from interface org.springframework.data.redis.support.collections.RedisZSet
addIfAbsent, rangeAndStoreByLex, rangeAndStoreByScore, rangeByLex, rangeByLex, rangeByLex, reverseRangeAndStoreByLex, reverseRangeAndStoreByScore, reverseRangeByLex, reverseRangeByLex, reverseRangeByLex
-
Constructor Details
-
DefaultRedisZSet
Constructs a newDefaultRedisZSet
instance with a default score of 1.- Parameters:
key
- Redis key of this set.operations
-RedisOperations
for the value type of this set.
-
DefaultRedisZSet
Constructs a newDefaultRedisZSet
instance.- Parameters:
key
- Redis key of this set.operations
-RedisOperations
for the value type of this set.defaultScore
-
-
DefaultRedisZSet
Constructs a newDefaultRedisZSet
instance with a default score of '1'.- Parameters:
boundOps
-BoundZSetOperations
for the value type of this set.
-
DefaultRedisZSet
Constructs a newDefaultRedisZSet
instance.- Parameters:
boundOps
-BoundZSetOperations
for the value type of this set.defaultScore
-
-
-
Method Details
-
diff
Description copied from interface:RedisZSet
Diff this set and anotherRedisZSet
. -
diff
Description copied from interface:RedisZSet
Diff this set and otherRedisZSet
s. -
diffWithScores
Description copied from interface:RedisZSet
Diff this set and anotherRedisZSet
.- Specified by:
diffWithScores
in interfaceRedisZSet<E>
- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the values that differ with their scores.
-
diffWithScores
Description copied from interface:RedisZSet
Diff this set and otherRedisZSet
s.- Specified by:
diffWithScores
in interfaceRedisZSet<E>
- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the values that differ with their scores.
-
diffAndStore
Description copied from interface:RedisZSet
Create a newRedisZSet
by diffing this sorted set andRedisZSet
and store result in destinationdestKey
.- Specified by:
diffAndStore
in interfaceRedisZSet<E>
- Parameters:
set
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
.
-
diffAndStore
Description copied from interface:RedisZSet
Create a newRedisZSet
by diffing this sorted set and the collectionRedisZSet
and store result in destinationdestKey
.- Specified by:
diffAndStore
in interfaceRedisZSet<E>
- Parameters:
sets
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
.
-
intersect
Description copied from interface:RedisZSet
Intersect this set and anotherRedisZSet
. -
intersect
Description copied from interface:RedisZSet
Intersect this set and otherRedisZSet
s. -
intersectWithScores
Description copied from interface:RedisZSet
Intersect this set and anotherRedisZSet
.- Specified by:
intersectWithScores
in interfaceRedisZSet<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 otherRedisZSet
s.- Specified by:
intersectWithScores
in interfaceRedisZSet<E>
- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the intersecting values with their scores.
-
intersectAndStore
Description copied from interface:RedisZSet
Create a newRedisZSet
by intersecting this sorted set andRedisZSet
and store result in destinationdestKey
.- Specified by:
intersectAndStore
in interfaceRedisZSet<E>
- Parameters:
set
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
intersectAndStore
Description copied from interface:RedisZSet
Create a newRedisZSet
by intersecting this sorted set and the collectionRedisZSet
and store result in destinationdestKey
.- Specified by:
intersectAndStore
in interfaceRedisZSet<E>
- Parameters:
sets
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
union
Description copied from interface:RedisZSet
Union this set and anotherRedisZSet
. -
union
Description copied from interface:RedisZSet
Union this set and otherRedisZSet
s. -
unionWithScores
Description copied from interface:RedisZSet
Union this set and anotherRedisZSet
.- Specified by:
unionWithScores
in interfaceRedisZSet<E>
- Parameters:
set
- must not be null.- Returns:
- a
Set
containing the combined values with their scores.
-
unionWithScores
Description copied from interface:RedisZSet
Union this set and otherRedisZSet
s.- Specified by:
unionWithScores
in interfaceRedisZSet<E>
- Parameters:
sets
- must not be null.- Returns:
- a
Set
containing the combined values with their scores.
-
unionAndStore
Description copied from interface:RedisZSet
Create a newRedisZSet
by union this sorted set andRedisZSet
and store result in destinationdestKey
.- Specified by:
unionAndStore
in interfaceRedisZSet<E>
- Parameters:
set
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
unionAndStore
Description copied from interface:RedisZSet
Create a newRedisZSet
by union this sorted set and the collectionRedisZSet
and store result in destinationdestKey
.- Specified by:
unionAndStore
in interfaceRedisZSet<E>
- Parameters:
sets
- must not be null.destKey
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
randomValue
Description copied from interface:RedisZSet
Get random element from the set.- Specified by:
randomValue
in interfaceRedisZSet<E>
- Returns:
-
range
Description copied from interface:RedisZSet
Get elements betweenstart
andend
from sorted set. -
reverseRange
Description copied from interface:RedisZSet
Get elements in range fromstart
toend
from sorted set ordered from high to low.- Specified by:
reverseRange
in interfaceRedisZSet<E>
- Returns:
-
rangeByLex
Description copied from interface:RedisZSet
Get all elements n elements, where n =Limit.getCount()
, starting atLimit.getOffset()
with lexicographical ordering having a value betweenRange.getLowerBound()
andRange.getUpperBound()
.- Specified by:
rangeByLex
in interfaceRedisZSet<E>
- Parameters:
range
- must not be null.limit
- can be null.- Returns:
- See Also:
-
reverseRangeByLex
Description copied from interface:RedisZSet
Get all elements n elements, where n =Limit.getCount()
, starting atLimit.getOffset()
with reverse lexicographical ordering having a value betweenRange.getLowerBound()
andRange.getUpperBound()
.- Specified by:
reverseRangeByLex
in interfaceRedisZSet<E>
- Parameters:
range
- must not be null.limit
- can be null.- Returns:
- See Also:
-
rangeByScore
Description copied from interface:RedisZSet
Get elements where score is betweenmin
andmax
from sorted set.- Specified by:
rangeByScore
in interfaceRedisZSet<E>
- Returns:
-
reverseRangeByScore
Description copied from interface:RedisZSet
Get elements where score is betweenmin
andmax
from sorted set ordered from high to low.- Specified by:
reverseRangeByScore
in interfaceRedisZSet<E>
- Returns:
-
rangeByScoreWithScores
Description copied from interface:RedisZSet
- Specified by:
rangeByScoreWithScores
in interfaceRedisZSet<E>
- Returns:
-
rangeWithScores
Description copied from interface:RedisZSet
- Specified by:
rangeWithScores
in interfaceRedisZSet<E>
- Returns:
-
reverseRangeByScoreWithScores
Description copied from interface:RedisZSet
- Specified by:
reverseRangeByScoreWithScores
in interfaceRedisZSet<E>
- Returns:
-
reverseRangeWithScores
Description copied from interface:RedisZSet
- Specified by:
reverseRangeWithScores
in interfaceRedisZSet<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 atdstKey
, where n =Limit.getCount()
, starting atLimit.getOffset()
with lexicographical ordering from ZSET at the bound key with a value betweenRange.getLowerBound()
andRange.getUpperBound()
.- Specified by:
rangeAndStoreByLex
in interfaceRedisZSet<E>
- Parameters:
dstKey
- must not be null.range
- must not be null.limit
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
- 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 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()
.- Specified by:
reverseRangeAndStoreByLex
in interfaceRedisZSet<E>
- Parameters:
dstKey
- must not be null.range
- must not be null.limit
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
- 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 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()
.- Specified by:
rangeAndStoreByScore
in interfaceRedisZSet<E>
- Parameters:
dstKey
- must not be null.range
- must not be null.limit
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
- 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 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()
.- Specified by:
reverseRangeAndStoreByScore
in interfaceRedisZSet<E>
- Parameters:
dstKey
- must not be null.range
- must not be null.limit
- must not be null.- Returns:
- a new
RedisZSet
pointing atdestKey
-
remove
Description copied from interface:RedisZSet
Remove elements in range betweenstart
andend
from sorted set. -
removeByLex
Description copied from interface:RedisZSet
Remove all elements in range.- Specified by:
removeByLex
in interfaceRedisZSet<E>
- Parameters:
range
- must not be null.- Returns:
this
set.
-
removeByScore
Description copied from interface:RedisZSet
Remove elements with scores betweenmin
andmax
from sorted set with the bound key.- Specified by:
removeByScore
in interfaceRedisZSet<E>
- Returns:
this
set.
-
add
Description copied from interface:RedisZSet
Adds an element to the set with a default score. Equivalent toadd(e, getDefaultScore())
. The score value is implementation specific. -
add
Description copied from interface:RedisZSet
Adds an element to the set with the given score, or updates the score if the element exists. -
addIfAbsent
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 interfaceRedisZSet<E>
- Parameters:
e
- element to addscore
- 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 interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
-
iterator
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
getDefaultScore
Description copied from interface:RedisZSet
Returns the default score used by this set.- Specified by:
getDefaultScore
in interfaceRedisZSet<E>
- Returns:
- the default score used by the implementation.
-
first
Description copied from interface:RedisZSet
Returns the first (lowest) element currently in this sorted set. -
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. -
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. Blocks connection until element available ortimeout
reached. -
last
Description copied from interface:RedisZSet
Returns the last (highest) element currently in this sorted set. -
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. -
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. Blocks connection until element available ortimeout
reached. -
rank
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. -
reverseRank
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 interfaceRedisZSet<E>
- Parameters:
o
- object- Returns:
- reverse rank of the given object
-
lexCount
Description copied from interface:RedisZSet
Count number of elements within sorted set with value betweenRange#min
andRange#max
applying lexicographical ordering. -
score
Description copied from interface:RedisZSet
Returns the score of the given element. Returns null if the element is not contained by the set. -
getType
Description copied from interface:BoundKeyOperations
Returns the associated Redis type.- Specified by:
getType
in interfaceBoundKeyOperations<E>
- Returns:
- key type. null when used in pipeline / transaction.
-
scan
-
scan
- Parameters:
options
-- Returns:
- Since:
- 1.4
-