Add Redis 2.6 srandmember with count to SetOperations
DATAREDIS-116
This commit is contained in:
@@ -62,6 +62,8 @@ public interface BoundSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
|
||||
V randomMember();
|
||||
|
||||
Set<V> randomMembers(long count);
|
||||
|
||||
Boolean remove(Object o);
|
||||
|
||||
V pop();
|
||||
|
||||
@@ -113,12 +113,17 @@ class DefaultBoundSetOperations<K, V> extends DefaultBoundKeyOperations<K> imple
|
||||
return ops.randomMember(getKey());
|
||||
}
|
||||
|
||||
|
||||
public Set<V> randomMembers(long count) {
|
||||
return ops.randomMembers(getKey(), count);
|
||||
}
|
||||
|
||||
|
||||
public Boolean remove(Object o) {
|
||||
return ops.remove(getKey(), o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public V pop() {
|
||||
return ops.pop(getKey());
|
||||
}
|
||||
|
||||
@@ -162,6 +162,18 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
||||
public Set<V> randomMembers(K key, final long count) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.sRandMember(rawKey, count);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
|
||||
public Boolean remove(K key, Object o) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
@@ -60,6 +60,8 @@ public interface SetOperations<K, V> {
|
||||
|
||||
V randomMember(K key);
|
||||
|
||||
Set<V> randomMembers(K key, long count);
|
||||
|
||||
Boolean remove(K key, Object o);
|
||||
|
||||
V pop(K key);
|
||||
|
||||
Reference in New Issue
Block a user