java.lang.Object
io.lettuce.core.protocol.Command<K,V,T>
- Type Parameters:
K- Key type.V- Value type.T- Command output type.
- All Implemented Interfaces:
RedisCommand<K,V,T>
public class Command<K,V,T> extends Object implements RedisCommand<K,V,T>
A Redis command with a
command type, arguments and an optional
output. All successfully executed commands will eventually return a CommandOutput object.- Author:
- Will Glozer, Mark Paluch
-
Field Summary
Fields Modifier and Type Field Description protected CommandArgs<K,V>argsprotected Throwableexceptionprotected CommandOutput<K,V,T>outputprotected static byteST_CANCELLEDprotected static byteST_COMPLETEDprotected static byteST_INITIALprotected bytestatus -
Constructor Summary
Constructors Constructor Description Command(ProtocolKeyword type, CommandOutput<K,V,T> output)Create a new command with the supplied type.Command(ProtocolKeyword type, CommandOutput<K,V,T> output, CommandArgs<K,V> args)Create a new command with the supplied type and args. -
Method Summary
Modifier and Type Method Description voidcancel()Attempts to cancel execution of this command.voidcomplete()Mark this command complete and notify all waiting threads.booleancompleteExceptionally(Throwable throwable)Complete this command by attaching the givenexception.voidencode(ByteBuf buf)Encode and write this command to the supplied buffer using the new Unified Request Protocol.Tget()CommandArgs<K,V>getArgs()StringgetError()CommandOutput<K,V,T>getOutput()Get the object that holds this command's output.ProtocolKeywordgetType()booleanisCancelled()Returnstrueif this task was cancelled before it completed normally.booleanisDone()Returnstrueif this task completed.voidsetOutput(CommandOutput<K,V,T> output)Set a new output.StringtoString()
-
Field Details
-
ST_INITIAL
protected static final byte ST_INITIAL- See Also:
- Constant Field Values
-
ST_COMPLETED
protected static final byte ST_COMPLETED- See Also:
- Constant Field Values
-
ST_CANCELLED
protected static final byte ST_CANCELLED- See Also:
- Constant Field Values
-
args
-
output
-
exception
-
status
protected volatile byte status
-
-
Constructor Details
-
Command
Create a new command with the supplied type.- Parameters:
type- Command type, must not benull.output- Command output, can benull.
-
Command
Create a new command with the supplied type and args.- Parameters:
type- Command type, must not benull.output- Command output, can benull.args- Command args, can benull
-
-
Method Details
-
getOutput
Get the object that holds this command's output.- Specified by:
getOutputin interfaceRedisCommand<K,V,T>- Returns:
- The command output object.
-
completeExceptionally
Description copied from interface:RedisCommandComplete this command by attaching the givenexception.- Specified by:
completeExceptionallyin interfaceRedisCommand<K,V,T>- Parameters:
throwable- the exception- Returns:
trueif this invocation caused this CompletableFuture to transition to a completed state, elsefalse
-
complete
public void complete()Mark this command complete and notify all waiting threads.- Specified by:
completein interfaceRedisCommand<K,V,T>
-
cancel
public void cancel()Description copied from interface:RedisCommandAttempts to cancel execution of this command. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason.- Specified by:
cancelin interfaceRedisCommand<K,V,T>
-
encode
Encode and write this command to the supplied buffer using the new Unified Request Protocol.- Specified by:
encodein interfaceRedisCommand<K,V,T>- Parameters:
buf- Buffer to write to.
-
getError
-
getArgs
- Specified by:
getArgsin interfaceRedisCommand<K,V,T>- Returns:
- the current command args.
-
get
- Returns:
- the resut from the output.
-
toString
-
setOutput
Description copied from interface:RedisCommandSet a new output. Only possible as long as the command is not completed/cancelled.- Specified by:
setOutputin interfaceRedisCommand<K,V,T>- Parameters:
output- the new command output
-
getType
- Specified by:
getTypein interfaceRedisCommand<K,V,T>- Returns:
- the Redis command type like
SADD,HMSET,QUIT.
-
isCancelled
public boolean isCancelled()Description copied from interface:RedisCommandReturnstrueif this task was cancelled before it completed normally.- Specified by:
isCancelledin interfaceRedisCommand<K,V,T>- Returns:
trueif the command was cancelled before it completed normally.
-
isDone
public boolean isDone()Description copied from interface:RedisCommandReturnstrueif this task completed. Completion may be due to normal termination, an exception, or cancellation. In all of these cases, this method will returntrue.- Specified by:
isDonein interfaceRedisCommand<K,V,T>- Returns:
trueif this task completed.
-