use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonLiveObjectService method findIds.
@Override
public <K> Iterable<K> findIds(Class<?> entityClass, int count) {
NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(entityClass);
String pattern = namingScheme.getNamePattern(entityClass);
RedissonKeys keys = new RedissonKeys(commandExecutor);
RedisCommand<ListScanResult<String>> command = new RedisCommand<>("SCAN", new ListMultiDecoder2(new ListScanResultReplayDecoder(), new ObjectListReplayDecoder<Object>()), new Convertor<Object>() {
@Override
public Object convert(Object obj) {
if (!(obj instanceof String)) {
return obj;
}
return namingScheme.resolveId(obj.toString());
}
});
return keys.getKeysByPattern(command, pattern, 0, count);
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonGeo method storeSearchToAsync.
@Override
public RFuture<Long> storeSearchToAsync(String destName, GeoSearchArgs args) {
GeoSearchNode node = (GeoSearchNode) args;
Map<GeoSearchNode.Params, Object> params = node.getParams();
List<Object> commandParams = new ArrayList<>();
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
commandParams.add(destName);
}
commandParams.add(getRawName());
RedisCommand command = null;
if (params.get(GeoSearchNode.Params.LATITUDE) != null && params.get(GeoSearchNode.Params.LONGITUDE) != null) {
command = RedisCommands.GEORADIUS_STORE;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = RedisCommands.GEOSEARCHSTORE_STORE;
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_STORE;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = RedisCommands.GEOSEARCHSTORE_STORE;
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));
}
if (params.get(GeoSearchNode.Params.HEIGHT) == null) {
commandParams.add("STORE");
commandParams.add(destName);
}
return commandExecutor.writeAsync(getRawName(), LongCodec.INSTANCE, command, commandParams.toArray());
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonGeo method searchWithDistanceAsync.
@Override
public RFuture<Map<V, Double>> searchWithDistanceAsync(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 = GEORADIUS_RO_DISTANCE;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = GEOSEARCH_DISTANCE;
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 = GEORADIUSBYMEMBER_RO_DISTANCE;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = GEOSEARCH_DISTANCE;
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.HEIGHT) == null) {
commandParams.add("WITHDIST");
}
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));
}
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
commandParams.add("WITHDIST");
}
return commandExecutor.readAsync(getRawName(), codec, command, commandParams.toArray());
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonGeo method hashAsync.
@Override
public RFuture<Map<V, String>> hashAsync(V... members) {
List<Object> params = new ArrayList<Object>(members.length + 1);
params.add(getRawName());
for (Object member : members) {
params.add(encode(member));
}
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder((List<Object>) Arrays.asList(members), 0));
return commandExecutor.readAsync(getRawName(), StringCodec.INSTANCE, command, params.toArray());
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class CommandAsyncService method evalAsync.
private <T, R> RFuture<R> evalAsync(NodeSource nodeSource, boolean readOnlyMode, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, boolean noRetry, Object... params) {
if (isEvalCacheActive() && evalCommandType.getName().equals("EVAL")) {
CompletableFuture<R> mainPromise = new CompletableFuture<>();
Object[] pps = copy(params);
CompletableFuture<R> promise = new CompletableFuture<>();
String sha1 = calcSHA(script);
RedisCommand cmd;
if (readOnlyMode && evalShaROSupported.get()) {
cmd = new RedisCommand(evalCommandType, "EVALSHA_RO");
} else {
cmd = new RedisCommand(evalCommandType, "EVALSHA");
}
List<Object> args = new ArrayList<Object>(2 + keys.size() + params.length);
args.add(sha1);
args.add(keys.size());
args.addAll(keys);
args.addAll(Arrays.asList(params));
RedisExecutor<T, R> executor = new RedisExecutor<>(readOnlyMode, nodeSource, codec, cmd, args.toArray(), promise, false, connectionManager, objectBuilder, referenceType, noRetry);
executor.execute();
promise.whenComplete((res, e) -> {
if (e != null) {
if (e.getMessage().startsWith("ERR unknown command")) {
evalShaROSupported.set(false);
free(pps);
RFuture<R> future = evalAsync(nodeSource, readOnlyMode, codec, evalCommandType, script, keys, noRetry, params);
transfer(future.toCompletableFuture(), mainPromise);
} else if (e.getMessage().startsWith("NOSCRIPT")) {
RFuture<String> loadFuture = loadScript(executor.getRedisClient(), script);
loadFuture.whenComplete((r, ex) -> {
if (ex != null) {
free(pps);
mainPromise.completeExceptionally(ex);
return;
}
List<Object> newargs = new ArrayList<Object>(2 + keys.size() + params.length);
newargs.add(sha1);
newargs.add(keys.size());
newargs.addAll(keys);
newargs.addAll(Arrays.asList(pps));
NodeSource ns = nodeSource;
if (ns.getRedisClient() == null) {
ns = new NodeSource(nodeSource, executor.getRedisClient());
}
RFuture<R> future = async(readOnlyMode, ns, codec, cmd, newargs.toArray(), false, noRetry);
transfer(future.toCompletableFuture(), mainPromise);
});
} else {
free(pps);
mainPromise.completeExceptionally(e);
}
return;
}
free(pps);
mainPromise.complete(res);
});
return new CompletableFutureWrapper<>(mainPromise);
}
List<Object> args = new ArrayList<Object>(2 + keys.size() + params.length);
args.add(script);
args.add(keys.size());
args.addAll(keys);
args.addAll(Arrays.asList(params));
return async(readOnlyMode, nodeSource, codec, evalCommandType, args.toArray(), false, noRetry);
}
Aggregations