use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonGeo method searchAsync.
@Override
public RFuture<List<V>> searchAsync(GeoSearchArgs args) {
GeoSearchNode node = (GeoSearchNode) args;
Map<GeoSearchNode.Params, Object> params = node.getParams();
List<Object> commandParams = new ArrayList<>();
commandParams.add(getRawName());
RedisCommand command = null;
if (params.get(GeoSearchNode.Params.LATITUDE) != null && params.get(GeoSearchNode.Params.LONGITUDE) != null) {
command = RedisCommands.GEORADIUS_RO;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = RedisCommands.GEOSEARCH;
commandParams.add("FROMLONLAT");
}
commandParams.add(convert((double) params.get(GeoSearchNode.Params.LONGITUDE)));
commandParams.add(convert((double) params.get(GeoSearchNode.Params.LATITUDE)));
}
if (params.get(GeoSearchNode.Params.MEMBER) != null) {
command = RedisCommands.GEORADIUSBYMEMBER_RO;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = RedisCommands.GEOSEARCH;
commandParams.add("FROMMEMBER");
}
commandParams.add(encode(params.get(GeoSearchNode.Params.MEMBER)));
}
if (params.get(GeoSearchNode.Params.RADIUS) != null && params.get(GeoSearchNode.Params.UNIT) != null) {
commandParams.add(params.get(GeoSearchNode.Params.RADIUS));
commandParams.add(params.get(GeoSearchNode.Params.UNIT));
}
if (params.get(GeoSearchNode.Params.HEIGHT) != null && params.get(GeoSearchNode.Params.UNIT) != null) {
commandParams.add("BYBOX");
commandParams.add(params.get(GeoSearchNode.Params.WIDTH));
commandParams.add(params.get(GeoSearchNode.Params.HEIGHT));
commandParams.add(params.get(GeoSearchNode.Params.UNIT));
if (params.get(GeoSearchNode.Params.ORDER) != null) {
commandParams.add(params.get(GeoSearchNode.Params.ORDER));
}
}
if (params.get(GeoSearchNode.Params.COUNT) != null) {
commandParams.add("COUNT");
commandParams.add(params.get(GeoSearchNode.Params.COUNT));
if (params.get(GeoSearchNode.Params.COUNT_ANY) != null) {
commandParams.add("ANY");
}
}
if (params.get(GeoSearchNode.Params.HEIGHT) == null && params.get(GeoSearchNode.Params.ORDER) != null) {
commandParams.add(params.get(GeoSearchNode.Params.ORDER));
}
return commandExecutor.readAsync(getRawName(), codec, command, commandParams.toArray());
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonScript method evalShaAsync.
@Override
public <R> RFuture<R> evalShaAsync(String key, Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values) {
RedisCommand command = new RedisCommand(returnType.getCommand(), "EVALSHA");
if (mode == Mode.READ_ONLY && commandExecutor.isEvalShaROSupported()) {
RedisCommand cmd = new RedisCommand(returnType.getCommand(), "EVALSHA_RO");
RFuture<R> f = commandExecutor.evalReadAsync(key, codec, cmd, shaDigest, keys, encode(Arrays.asList(values), codec).toArray());
CompletableFuture<R> result = new CompletableFuture<>();
f.whenComplete((r, e) -> {
if (e != null && e.getMessage().startsWith("ERR unknown command")) {
commandExecutor.setEvalShaROSupported(false);
RFuture<R> s = evalShaAsync(key, mode, shaDigest, returnType, keys, values);
commandExecutor.transfer(s.toCompletableFuture(), result);
return;
}
commandExecutor.transfer(f.toCompletableFuture(), result);
});
return new CompletableFutureWrapper<>(result);
}
return commandExecutor.evalWriteAsync(key, codec, command, shaDigest, keys, encode(Arrays.asList(values), codec).toArray());
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class CommandAsyncService method executeAll.
@Override
public <R> List<CompletableFuture<R>> executeAll(RedisCommand<?> command, Object... params) {
Collection<MasterSlaveEntry> nodes = connectionManager.getEntrySet();
List<CompletableFuture<R>> futures = new ArrayList<>();
nodes.forEach(e -> {
RFuture<R> promise = async(false, new NodeSource(e), connectionManager.getCodec(), command, params, true, false);
futures.add(promise.toCompletableFuture());
e.getAllEntries().stream().filter(c -> c.getNodeType() == NodeType.SLAVE).forEach(c -> {
RFuture<R> slavePromise = async(true, new NodeSource(e, c.getClient()), connectionManager.getCodec(), RedisCommands.SCRIPT_LOAD, params, true, false);
futures.add(slavePromise.toCompletableFuture());
});
});
return futures;
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonBuckets method get.
@Override
public <V> Map<String, V> get(String... keys) {
if (keys.length == 0) {
return Collections.emptyMap();
}
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0), ValueType.OBJECTS);
RFuture<Map<String, V>> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys);
return commandExecutor.get(future);
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonReactiveListCommands method popList.
@Override
public Flux<CommandResponse<PopCommand, Flux<ByteBuffer>>> popList(Publisher<PopCommand> commands) {
return execute(commands, command -> {
Assert.notNull(command.getKey(), "Key must not be null!");
byte[] keyBuf = toByteArray(command.getKey());
RedisCommand cmd;
if (command.getDirection() == Direction.RIGHT) {
cmd = RedisCommands.RPOP_LIST;
} else {
cmd = RedisCommands.LPOP_LIST;
}
List<Object> params = new ArrayList<>(2);
params.add(keyBuf);
if (command.getCount() > 0) {
params.add(command.getCount());
}
Mono<List<byte[]>> m = write(keyBuf, ByteArrayCodec.INSTANCE, cmd, params.toArray());
return m.map(v -> new CommandResponse<>(command, Flux.fromIterable(v).map(e -> ByteBuffer.wrap(e))));
});
}
Aggregations