org.infinispan.server.resp.commands.tx.MULTI Maven / Gradle / Ivy
Show all versions of infinispan-server-resp Show documentation
package org.infinispan.server.resp.commands.tx;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import org.infinispan.server.resp.Consumers;
import org.infinispan.server.resp.Resp3Handler;
import org.infinispan.server.resp.RespCommand;
import org.infinispan.server.resp.RespErrorUtil;
import org.infinispan.server.resp.RespRequestHandler;
import org.infinispan.server.resp.commands.Resp3Command;
import org.infinispan.server.resp.commands.TransactionResp3Command;
import org.infinispan.server.resp.tx.RespTransactionHandler;
import io.netty.channel.ChannelHandlerContext;
/**
* `MULTI
` command.
*
* This command marks the start of a transaction block. Subsequent operations are queued for later execution and receive
* a {@link org.infinispan.server.resp.RespConstants#QUEUED_REPLY} response. Each operation is verified for errors,
* for example, the number of arguments. Flawed operations receive the corresponding error reply and are discarded.
* Although, these errors do not abort the transaction.
*
* Sending "nested" MULTI commands is not accepted, i.e., sending a MULTI command when already in a MULTI context.
* Again, this does not abort the transaction but returns an error.
*
* Redis also does not include a rollback command. Instead, the user can send a DISCARD command to abort the transaction,
* clearing the queued commands and exiting the transaction context. Other commands with similar behavior are
* {@link org.infinispan.server.resp.commands.connection.QUIT}, {@link org.infinispan.server.resp.commands.pubsub.SUBSCRIBE},
* and {@link org.infinispan.server.resp.commands.pubsub.PSUBSCRIBE}. The subscription commands drop the queued commands
* and enter pub-sub mode.
*
* @since 15.0
* @see Redis documentation
* @see Redis transactions documentation
* @author José Bolina
*/
public class MULTI extends RespCommand implements Resp3Command, TransactionResp3Command {
public MULTI() {
super(1, 0, 0, 0);
}
@Override
public CompletionStage perform(Resp3Handler handler, ChannelHandlerContext ctx, List arguments) {
Consumers.OK_BICONSUMER.accept(null, handler.allocator());
return CompletableFuture.completedFuture(new RespTransactionHandler(handler.respServer()));
}
@Override
public CompletionStage perform(RespTransactionHandler handler, ChannelHandlerContext ctx, List arguments) {
RespErrorUtil.customError("MULTI calls can not be nested", handler.allocator());
return handler.myStage();
}
}