Search in sources :

Example 16 with RedisCommand

use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.

the class CommandAsyncService method async.

public <V, R> RFuture<R> async(boolean readOnlyMode, NodeSource source, Codec codec, RedisCommand<V> command, Object[] params, boolean ignoreRedirect, boolean noRetry) {
    if (readOnlyMode && command.getName().equals("SORT") && !sortRoSupported.get()) {
        readOnlyMode = false;
    } else if (readOnlyMode && command.getName().equals("SORT") && sortRoSupported.get()) {
        RedisCommand cmd = new RedisCommand("SORT_RO", command.getReplayMultiDecoder());
        CompletableFuture<R> mainPromise = createPromise();
        RedisExecutor<V, R> executor = new RedisExecutor<>(readOnlyMode, source, codec, cmd, params, mainPromise, ignoreRedirect, connectionManager, objectBuilder, referenceType, noRetry);
        executor.execute();
        CompletableFuture<R> result = new CompletableFuture<>();
        mainPromise.whenComplete((r, e) -> {
            if (e != null && e.getMessage().startsWith("ERR unknown command")) {
                sortRoSupported.set(false);
                RFuture<R> future = async(false, source, codec, command, params, ignoreRedirect, noRetry);
                transfer(future.toCompletableFuture(), result);
                return;
            }
            transfer(mainPromise, result);
        });
        return new CompletableFutureWrapper<>(result);
    }
    CompletableFuture<R> mainPromise = createPromise();
    RedisExecutor<V, R> executor = new RedisExecutor<>(readOnlyMode, source, codec, command, params, mainPromise, ignoreRedirect, connectionManager, objectBuilder, referenceType, noRetry);
    executor.execute();
    return new CompletableFutureWrapper<>(mainPromise);
}
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) RFuture(org.redisson.api.RFuture) CompletableFuture(java.util.concurrent.CompletableFuture) CompletableFutureWrapper(org.redisson.misc.CompletableFutureWrapper) RedisCommand(org.redisson.client.protocol.RedisCommand)

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