|
|
@ -15,10 +15,9 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.redisson.command;
|
|
|
|
package org.redisson.command;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import io.netty.channel.ChannelFuture;
|
|
|
|
import java.util.List;
|
|
|
|
import io.netty.channel.ChannelFutureListener;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
import io.netty.channel.ChannelPromise;
|
|
|
|
|
|
|
|
|
|
|
|
import org.redisson.api.BatchOptions;
|
|
|
|
import org.redisson.api.BatchOptions;
|
|
|
|
import org.redisson.api.BatchOptions.ExecutionMode;
|
|
|
|
import org.redisson.api.BatchOptions.ExecutionMode;
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
@ -37,6 +36,10 @@ import org.redisson.misc.RedissonPromise;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Nikita Koksharov
|
|
|
|
* @author Nikita Koksharov
|
|
|
@ -97,7 +100,7 @@ public class RedisCommonBatchExecutor extends RedisExecutor<Object, Void> {
|
|
|
|
List<CommandData<?, ?>> list = new ArrayList<>(entry.getCommands().size());
|
|
|
|
List<CommandData<?, ?>> list = new ArrayList<>(entry.getCommands().size());
|
|
|
|
if (source.getRedirect() == Redirect.ASK) {
|
|
|
|
if (source.getRedirect() == Redirect.ASK) {
|
|
|
|
RPromise<Void> promise = new RedissonPromise<Void>();
|
|
|
|
RPromise<Void> promise = new RedissonPromise<Void>();
|
|
|
|
list.add(new CommandData<Void, Void>(promise, StringCodec.INSTANCE, RedisCommands.ASKING, new Object[] {}));
|
|
|
|
list.add(new CommandData<>(promise, StringCodec.INSTANCE, RedisCommands.ASKING, new Object[] {}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (CommandData<?, ?> c : entry.getCommands()) {
|
|
|
|
for (CommandData<?, ?> c : entry.getCommands()) {
|
|
|
|
if ((c.getPromise().isCancelled() || c.getPromise().isSuccess())
|
|
|
|
if ((c.getPromise().isCancelled() || c.getPromise().isSuccess())
|
|
|
@ -115,7 +118,37 @@ public class RedisCommonBatchExecutor extends RedisExecutor<Object, Void> {
|
|
|
|
timeout.cancel();
|
|
|
|
timeout.cancel();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sendCommand(connection, attemptPromise, list);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void sendCommand(RedisConnection connection, RPromise<Void> attemptPromise, List<CommandData<?, ?>> list) {
|
|
|
|
|
|
|
|
boolean isAtomic = options.getExecutionMode() != ExecutionMode.IN_MEMORY;
|
|
|
|
|
|
|
|
boolean isQueued = options.getExecutionMode() == ExecutionMode.REDIS_READ_ATOMIC
|
|
|
|
|
|
|
|
|| options.getExecutionMode() == ExecutionMode.REDIS_WRITE_ATOMIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandData<?, ?> lastCommand = connection.getLastCommand();
|
|
|
|
|
|
|
|
if (lastCommand != null && options.isSkipResult()) {
|
|
|
|
|
|
|
|
writeFuture = connection.getChannel().newPromise();
|
|
|
|
|
|
|
|
lastCommand.getPromise().onComplete((r, e) -> {
|
|
|
|
|
|
|
|
CommandData<?, ?> currentLastCommand = connection.getLastCommand();
|
|
|
|
|
|
|
|
if (lastCommand != currentLastCommand && currentLastCommand != null) {
|
|
|
|
|
|
|
|
sendCommand(connection, attemptPromise, list);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChannelFuture wf = connection.send(new CommandsData(attemptPromise, list, options.isSkipResult(), isAtomic, isQueued, options.getSyncSlaves() > 0));
|
|
|
|
|
|
|
|
wf.addListener((ChannelFutureListener) future -> {
|
|
|
|
|
|
|
|
if (future.isSuccess()) {
|
|
|
|
|
|
|
|
((ChannelPromise) writeFuture).trySuccess(future.getNow());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
((ChannelPromise) writeFuture).tryFailure(future.cause());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
writeFuture = connection.send(new CommandsData(attemptPromise, list, options.isSkipResult(), isAtomic, isQueued, options.getSyncSlaves() > 0));
|
|
|
|
writeFuture = connection.send(new CommandsData(attemptPromise, list, options.isSkipResult(), isAtomic, isQueued, options.getSyncSlaves() > 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|