Support ZRANDMEMBER via RedisZSet.
Add randomValue() method to both RedisZSet and RedisSet. See: #2049 Original Pull Request: #2104
This commit is contained in:
@@ -187,6 +187,15 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
|
||||
return new DefaultRedisSet<>(boundSetOps.getOperations().boundSetOps(destKey));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisSet#randomElement()
|
||||
*/
|
||||
@Override
|
||||
public E randomValue() {
|
||||
return boundSetOps.randomMember();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.util.AbstractCollection#add(java.lang.Object)
|
||||
|
||||
@@ -277,6 +277,15 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
return new DefaultRedisZSet<>(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#randomElement()
|
||||
*/
|
||||
@Override
|
||||
public E randomValue() {
|
||||
return boundZSetOps.randomMember();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#range(long, long)
|
||||
|
||||
@@ -82,8 +82,8 @@ public interface RedisSet<E> extends RedisCollection<E>, Set<E> {
|
||||
Set<E> diff(Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
/**
|
||||
* Create a new {@link RedisSet} by intersecting this sorted set and {@link RedisSet} and store result in
|
||||
* destination {@code destKey}.
|
||||
* Create a new {@link RedisSet} by intersecting this sorted set and {@link RedisSet} and store result in destination
|
||||
* {@code destKey}.
|
||||
*
|
||||
* @param set must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
@@ -93,8 +93,8 @@ public interface RedisSet<E> extends RedisCollection<E>, Set<E> {
|
||||
RedisSet<E> intersectAndStore(RedisSet<?> set, String destKey);
|
||||
|
||||
/**
|
||||
* Create a new {@link RedisSet} by intersecting this sorted set and the collection {@link RedisSet} and store
|
||||
* result in destination {@code destKey}.
|
||||
* Create a new {@link RedisSet} by intersecting this sorted set and the collection {@link RedisSet} and store result
|
||||
* in destination {@code destKey}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
@@ -125,6 +125,14 @@ public interface RedisSet<E> extends RedisCollection<E>, Set<E> {
|
||||
*/
|
||||
RedisSet<E> unionAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
|
||||
|
||||
/**
|
||||
* Get random element from the set.
|
||||
*
|
||||
* @return
|
||||
* @since 2.6
|
||||
*/
|
||||
E randomValue();
|
||||
|
||||
/**
|
||||
* Create a new {@link RedisSet} by diffing this sorted set and {@link RedisSet} and store result in destination
|
||||
* {@code destKey}.
|
||||
|
||||
@@ -236,6 +236,14 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
*/
|
||||
RedisZSet<E> unionAndStore(Collection<? extends RedisZSet<?>> sets, String destKey);
|
||||
|
||||
/**
|
||||
* Get random element from the set.
|
||||
*
|
||||
* @return
|
||||
* @since 2.6
|
||||
*/
|
||||
E randomValue();
|
||||
|
||||
/**
|
||||
* Get elements between {@code start} and {@code end} from sorted set.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user