readAll and readAllAsync methods added to RSet. #374

pull/382/head
Nikita 9 years ago
parent fac707f840
commit cdcf1bdfa1

@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommands;
@ -143,19 +144,25 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
};
}
private Future<Collection<V>> readAllAsync() {
@Override
public Future<Set<V>> readAllAsync() {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SMEMBERS, getName());
}
@Override
public Set<V> readAll() {
return get(readAllAsync());
}
@Override
public Object[] toArray() {
List<Object> res = (List<Object>) get(readAllAsync());
Set<Object> res = (Set<Object>) get(readAllAsync());
return res.toArray();
}
@Override
public <T> T[] toArray(T[] a) {
List<Object> res = (List<Object>) get(readAllAsync());
Set<Object> res = (Set<Object>) get(readAllAsync());
return res.toArray(a);
}

@ -110,7 +110,7 @@ public interface RedisCommands {
RedisCommand<Boolean> SADD_SINGLE = new RedisCommand<Boolean>("SADD", new BooleanReplayConvertor(), 2);
RedisCommand<Boolean> SREM_SINGLE = new RedisCommand<Boolean>("SREM", new BooleanReplayConvertor(), 2);
RedisCommand<Boolean> SMOVE = new RedisCommand<Boolean>("SMOVE", new BooleanReplayConvertor(), 3);
RedisCommand<List<Object>> SMEMBERS = new RedisCommand<List<Object>>("SMEMBERS", new ObjectListReplayDecoder<Object>());
RedisCommand<Set<Object>> SMEMBERS = new RedisCommand<Set<Object>>("SMEMBERS", new ObjectSetReplayDecoder());
RedisCommand<ListScanResult<Object>> SSCAN = new RedisCommand<ListScanResult<Object>>("SSCAN", new NestedMultiDecoder(new ObjectListReplayDecoder<Object>(), new ListScanResultReplayDecoder()), ValueType.OBJECT);
RedisCommand<ListScanResult<Object>> EVAL_SSCAN = new RedisCommand<ListScanResult<Object>>("EVAL", new NestedMultiDecoder(new ObjectListReplayDecoder<Object>(), new ListScanResultReplayDecoder()), ValueType.OBJECT);
RedisCommand<Boolean> SISMEMBER = new RedisCommand<Boolean>("SISMEMBER", new BooleanReplayConvertor(), 2);

@ -43,4 +43,11 @@ public interface RSet<V> extends Set<V>, RExpirable, RSetAsync<V> {
*/
boolean move(String destination, V member);
/**
* Read all elements at once
*
* @return
*/
Set<V> readAll();
}

@ -15,6 +15,8 @@
*/
package org.redisson.core;
import java.util.Set;
import io.netty.util.concurrent.Future;
/**
@ -44,4 +46,11 @@ public interface RSetAsync<V> extends RCollectionAsync<V> {
*/
Future<Boolean> moveAsync(String destination, V member);
/**
* Read all elements at once
*
* @return
*/
Future<Set<V>> readAllAsync();
}

Loading…
Cancel
Save