Search in sources :

Example 6 with RedisCommand

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());
}
Also used : GeoSearchNode(org.redisson.api.geo.GeoSearchNode) RedisCommand(org.redisson.client.protocol.RedisCommand)

Example 7 with RedisCommand

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());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) CompletableFutureWrapper(org.redisson.misc.CompletableFutureWrapper) RedisCommand(org.redisson.client.protocol.RedisCommand)

Example 8 with RedisCommand

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;
}
Also used : RedisException(org.redisson.client.RedisException) RPromise(org.redisson.misc.RPromise) java.util(java.util) NodeType(org.redisson.api.NodeType) Codec(org.redisson.client.codec.Codec) StringCodec(org.redisson.client.codec.StringCodec) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) MessageDigest(java.security.MessageDigest) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) RedisClient(org.redisson.client.RedisClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) RFuture(org.redisson.api.RFuture) NodeSource(org.redisson.connection.NodeSource) CompletableFutureWrapper(org.redisson.misc.CompletableFutureWrapper) ByteBuf(io.netty.buffer.ByteBuf) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) RedissonReference(org.redisson.RedissonReference) SlotCallback(org.redisson.SlotCallback) Logger(org.slf4j.Logger) LRUCacheMap(org.redisson.cache.LRUCacheMap) ConnectionManager(org.redisson.connection.ConnectionManager) RedissonPromise(org.redisson.misc.RedissonPromise) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) RedisCommands(org.redisson.client.protocol.RedisCommands) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) ByteBufUtil(io.netty.buffer.ByteBufUtil) RedisRedirectException(org.redisson.client.RedisRedirectException) CompletionStage(java.util.concurrent.CompletionStage) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) Entry(java.util.Map.Entry) RedisCommand(org.redisson.client.protocol.RedisCommand) RedissonObjectBuilder(org.redisson.liveobject.core.RedissonObjectBuilder) NodeSource(org.redisson.connection.NodeSource) CompletableFuture(java.util.concurrent.CompletableFuture) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry)

Example 9 with RedisCommand

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);
}
Also used : RedisCommand(org.redisson.client.protocol.RedisCommand) MapGetAllDecoder(org.redisson.connection.decoder.MapGetAllDecoder) DelegateDecoderCodec(org.redisson.client.codec.DelegateDecoderCodec) Map(java.util.Map)

Example 10 with RedisCommand

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))));
    });
}
Also used : RedisCommand(org.redisson.client.protocol.RedisCommand) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

RedisCommand (org.redisson.client.protocol.RedisCommand)16 GeoSearchNode (org.redisson.api.geo.GeoSearchNode)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 RFuture (org.redisson.api.RFuture)4 Codec (org.redisson.client.codec.Codec)4 StringCodec (org.redisson.client.codec.StringCodec)4 MapGetAllDecoder (org.redisson.connection.decoder.MapGetAllDecoder)4 CompletableFutureWrapper (org.redisson.misc.CompletableFutureWrapper)4 ByteBuf (io.netty.buffer.ByteBuf)3 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)3 ByteBufUtil (io.netty.buffer.ByteBufUtil)3 ReferenceCountUtil (io.netty.util.ReferenceCountUtil)3 IOException (java.io.IOException)3 MessageDigest (java.security.MessageDigest)3 java.util (java.util)3 Entry (java.util.Map.Entry)3 CompletionStage (java.util.concurrent.CompletionStage)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3