Search in sources :

Example 1 with Entry

use of org.redisson.command.CommandBatchService.Entry in project redisson by redisson.

the class BaseRedisBatchExecutor method addBatchCommandData.

protected final void addBatchCommandData(Object[] batchParams) {
    MasterSlaveEntry msEntry = getEntry(source);
    Entry entry = commands.get(msEntry);
    if (entry == null) {
        entry = new Entry();
        Entry oldEntry = commands.putIfAbsent(msEntry, entry);
        if (oldEntry != null) {
            entry = oldEntry;
        }
    }
    if (!readOnlyMode) {
        entry.setReadOnlyMode(false);
    }
    Codec codecToUse = getCodec(codec);
    BatchCommandData<V, R> commandData = new BatchCommandData<V, R>(mainPromise, codecToUse, command, batchParams, index.incrementAndGet());
    entry.getCommands().add(commandData);
}
Also used : MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) Entry(org.redisson.command.CommandBatchService.Entry) Codec(org.redisson.client.codec.Codec) BatchCommandData(org.redisson.client.protocol.BatchCommandData) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry)

Example 2 with Entry

use of org.redisson.command.CommandBatchService.Entry in project redisson by redisson.

the class RedisQueuedBatchExecutor method sendCommand.

@Override
protected void sendCommand(CompletableFuture<R> attemptPromise, RedisConnection connection) {
    MasterSlaveEntry msEntry = getEntry(source);
    ConnectionEntry connectionEntry = connections.get(msEntry);
    boolean syncSlaves = options.getSyncSlaves() > 0;
    if (source.getRedirect() == Redirect.ASK) {
        List<CommandData<?, ?>> list = new ArrayList<>(2);
        CompletableFuture<Void> promise = new CompletableFuture<>();
        list.add(new CommandData<>(promise, codec, RedisCommands.ASKING, new Object[] {}));
        if (connectionEntry.isFirstCommand()) {
            list.add(new CommandData<>(promise, codec, RedisCommands.MULTI, new Object[] {}));
            connectionEntry.setFirstCommand(false);
        }
        list.add(new CommandData<>(attemptPromise, codec, command, params));
        CompletableFuture<Void> main = new CompletableFuture<>();
        writeFuture = connection.send(new CommandsData(main, list, true, syncSlaves));
    } else {
        if (log.isDebugEnabled()) {
            log.debug("acquired connection for command {} and params {} from slot {} using node {}... {}", command, LogHelper.toString(params), source, connection.getRedisClient().getAddr(), connection);
        }
        if (connectionEntry.isFirstCommand()) {
            List<CommandData<?, ?>> list = new ArrayList<>(2);
            list.add(new CommandData<>(new CompletableFuture<>(), codec, RedisCommands.MULTI, new Object[] {}));
            list.add(new CommandData<>(attemptPromise, codec, command, params));
            CompletableFuture<Void> main = new CompletableFuture<>();
            writeFuture = connection.send(new CommandsData(main, list, true, syncSlaves));
            connectionEntry.setFirstCommand(false);
        } else {
            if (RedisCommands.EXEC.getName().equals(command.getName())) {
                Entry entry = commands.get(msEntry);
                List<CommandData<?, ?>> list = new ArrayList<>();
                if (options.isSkipResult()) {
                    list.add(new CommandData<>(new CompletableFuture<>(), codec, RedisCommands.CLIENT_REPLY, new Object[] { "OFF" }));
                }
                list.add(new CommandData<>(attemptPromise, codec, command, params));
                if (options.isSkipResult()) {
                    list.add(new CommandData<>(new CompletableFuture<>(), codec, RedisCommands.CLIENT_REPLY, new Object[] { "ON" }));
                }
                if (options.getSyncSlaves() > 0) {
                    BatchCommandData<?, ?> waitCommand = new BatchCommandData(RedisCommands.WAIT, new Object[] { this.options.getSyncSlaves(), this.options.getSyncTimeout() }, index.incrementAndGet());
                    list.add(waitCommand);
                    entry.getCommands().add(waitCommand);
                }
                CompletableFuture<Void> main = new CompletableFuture<>();
                writeFuture = connection.send(new CommandsData(main, list, new ArrayList(entry.getCommands()), options.isSkipResult(), false, true, syncSlaves));
            } else {
                CompletableFuture<Void> main = new CompletableFuture<>();
                List<CommandData<?, ?>> list = new ArrayList<>();
                list.add(new CommandData<>(attemptPromise, codec, command, params));
                writeFuture = connection.send(new CommandsData(main, list, true, syncSlaves));
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionEntry(org.redisson.command.CommandBatchService.ConnectionEntry) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) Entry(org.redisson.command.CommandBatchService.Entry) ConnectionEntry(org.redisson.command.CommandBatchService.ConnectionEntry) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry)

Aggregations

Entry (org.redisson.command.CommandBatchService.Entry)2 MasterSlaveEntry (org.redisson.connection.MasterSlaveEntry)2 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Codec (org.redisson.client.codec.Codec)1 BatchCommandData (org.redisson.client.protocol.BatchCommandData)1 ConnectionEntry (org.redisson.command.CommandBatchService.ConnectionEntry)1