Package io.lettuce.core.protocol
Class Command<K,V,T>
- 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 acommand type
,arguments
and an optionaloutput
. All successfully executed commands will eventually return aCommandOutput
object.- Author:
- Will Glozer, Mark Paluch
-
-
Field Summary
Fields Modifier and Type Field Description protected CommandArgs<K,V>
args
protected Throwable
exception
protected CommandOutput<K,V,T>
output
protected static byte
ST_CANCELLED
protected static byte
ST_COMPLETED
protected static byte
ST_INITIAL
protected byte
status
-
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Attempts to cancel execution of this command.void
complete()
Mark this command complete and notify all waiting threads.boolean
completeExceptionally(Throwable throwable)
Complete this command by attaching the givenexception
.void
encode(ByteBuf buf)
Encode and write this command to the supplied buffer using the new Unified Request Protocol.T
get()
CommandArgs<K,V>
getArgs()
String
getError()
CommandOutput<K,V,T>
getOutput()
Get the object that holds this command's output.ProtocolKeyword
getType()
boolean
isCancelled()
Returnstrue
if this task was cancelled before it completed normally.boolean
isDone()
Returnstrue
if this task completed.void
setOutput(CommandOutput<K,V,T> output)
Set a new output.String
toString()
-
-
-
Field Detail
-
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
protected CommandArgs<K,V> args
-
output
protected CommandOutput<K,V,T> output
-
exception
protected Throwable exception
-
status
protected volatile byte status
-
-
Constructor Detail
-
Command
public Command(ProtocolKeyword type, CommandOutput<K,V,T> output)
Create a new command with the supplied type.- Parameters:
type
- Command type, must not benull
.output
- Command output, can benull
.
-
Command
public Command(ProtocolKeyword type, CommandOutput<K,V,T> output, CommandArgs<K,V> args)
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 Detail
-
getOutput
public CommandOutput<K,V,T> getOutput()
Get the object that holds this command's output.- Specified by:
getOutput
in interfaceRedisCommand<K,V,T>
- Returns:
- The command output object.
-
completeExceptionally
public boolean completeExceptionally(Throwable throwable)
Description copied from interface:RedisCommand
Complete this command by attaching the givenexception
.- Specified by:
completeExceptionally
in interfaceRedisCommand<K,V,T>
- Parameters:
throwable
- the exception- Returns:
true
if 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:
complete
in interfaceRedisCommand<K,V,T>
-
cancel
public void cancel()
Description copied from interface:RedisCommand
Attempts 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:
cancel
in interfaceRedisCommand<K,V,T>
-
encode
public void encode(ByteBuf buf)
Encode and write this command to the supplied buffer using the new Unified Request Protocol.- Specified by:
encode
in interfaceRedisCommand<K,V,T>
- Parameters:
buf
- Buffer to write to.
-
getError
public String getError()
-
getArgs
public CommandArgs<K,V> getArgs()
- Specified by:
getArgs
in interfaceRedisCommand<K,V,T>
- Returns:
- the current command args.
-
get
public T get()
- Returns:
- the resut from the output.
-
setOutput
public void setOutput(CommandOutput<K,V,T> output)
Description copied from interface:RedisCommand
Set a new output. Only possible as long as the command is not completed/cancelled.- Specified by:
setOutput
in interfaceRedisCommand<K,V,T>
- Parameters:
output
- the new command output
-
getType
public ProtocolKeyword getType()
- Specified by:
getType
in interfaceRedisCommand<K,V,T>
- Returns:
- the Redis command type like
SADD
,HMSET
,QUIT
.
-
isCancelled
public boolean isCancelled()
Description copied from interface:RedisCommand
Returnstrue
if this task was cancelled before it completed normally.- Specified by:
isCancelled
in interfaceRedisCommand<K,V,T>
- Returns:
true
if the command was cancelled before it completed normally.
-
isDone
public boolean isDone()
Description copied from interface:RedisCommand
Returnstrue
if 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:
isDone
in interfaceRedisCommand<K,V,T>
- Returns:
true
if this task completed.
-
-