refactoring

pull/4748/head
Nikita Koksharov 2 years ago
parent f3d891d54e
commit 1f45b65e25

@ -26,6 +26,7 @@ import org.redisson.mapreduce.RedissonCollectionMapReduce;
import org.redisson.misc.CompletableFutureWrapper; import org.redisson.misc.CompletableFutureWrapper;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletionStage;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@ -379,7 +380,7 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V>, ScanIt
return new CompletableFutureWrapper<>(0); return new CompletableFutureWrapper<>(0);
} }
List<Object> args = new ArrayList<Object>(c.size() + 1); List<Object> args = new ArrayList<>(c.size() + 1);
args.add(getRawName()); args.add(getRawName());
encode(args, c); encode(args, c);
@ -389,29 +390,25 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V>, ScanIt
@Override @Override
public RFuture<List<V>> containsEachAsync(Collection<V> c) { public RFuture<List<V>> containsEachAsync(Collection<V> c) {
if (c.isEmpty()) { if (c.isEmpty()) {
return RedissonPromise.newSucceededFuture(Collections.emptyList()); return new CompletableFutureWrapper<>(Collections.emptyList());
} }
List<Object> args = new ArrayList<Object>(c.size() + 1);
List<Object> args = new ArrayList<>(c.size() + 1);
args.add(getRawName()); args.add(getRawName());
encode(args, c); encode(args, c);
RFuture<List<Long>> future = commandExecutor.readAsync(getRawName(), codec, RedisCommands.SMISMEMBER, args.toArray()); RFuture<List<Long>> future = commandExecutor.readAsync(getRawName(), codec, RedisCommands.SMISMEMBER, args.toArray());
List<V> keysToCheck = new ArrayList<>(c); List<V> keysToCheck = new ArrayList<>(c);
RPromise<List<V>> result = new RedissonPromise<>(); CompletionStage<List<V>> f = future.thenApply(res -> {
future.onComplete((res, e) -> {
if (e != null) {
result.tryFailure(e);
return;
}
List<V> containedKeys = new ArrayList<>(); List<V> containedKeys = new ArrayList<>();
for (int i = 0; i < res.size(); i++) { for (int i = 0; i < res.size(); i++) {
if (res.get(i) == 1) { if (res.get(i) == 1) {
containedKeys.add(keysToCheck.get(i)); containedKeys.add(keysToCheck.get(i));
} }
} }
result.trySuccess(containedKeys); return containedKeys;
}); });
return result; return new CompletableFutureWrapper<>(f);
} }
@Override @Override

@ -215,7 +215,7 @@ public interface RedisCommands {
RedisCommand<Set<Object>> SUNION = new RedisCommand<Set<Object>>("SUNION", new ObjectSetReplayDecoder<Object>()); RedisCommand<Set<Object>> SUNION = new RedisCommand<Set<Object>>("SUNION", new ObjectSetReplayDecoder<Object>());
RedisCommand<Set<Object>> SDIFF = new RedisCommand<Set<Object>>("SDIFF", new ObjectSetReplayDecoder<Object>()); RedisCommand<Set<Object>> SDIFF = new RedisCommand<Set<Object>>("SDIFF", new ObjectSetReplayDecoder<Object>());
RedisCommand<Set<Object>> SINTER = new RedisCommand<Set<Object>>("SINTER", new ObjectSetReplayDecoder<Object>()); RedisCommand<Set<Object>> SINTER = new RedisCommand<Set<Object>>("SINTER", new ObjectSetReplayDecoder<Object>());
RedisCommand<List<Long>> SMISMEMBER = new RedisCommand<List<Long>>("SMISMEMBER", new ObjectListReplayDecoder<Long>()); RedisCommand<List<Long>> SMISMEMBER = new RedisCommand<>("SMISMEMBER", new ObjectListReplayDecoder<Long>());
RedisStrictCommand<Long> LPOS = new RedisStrictCommand<>("LPOS"); RedisStrictCommand<Long> LPOS = new RedisStrictCommand<>("LPOS");
RedisCommand<Void> LSET = new RedisCommand<Void>("LSET", new VoidReplayConvertor()); RedisCommand<Void> LSET = new RedisCommand<Void>("LSET", new VoidReplayConvertor());

Loading…
Cancel
Save