Module lettuce.core

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 a command type, arguments and an optional output. All successfully executed commands will eventually return a CommandOutput object.
Author:
Will Glozer, Mark Paluch
  • Field Details

  • Constructor Details

    • Command

      public Command​(ProtocolKeyword type, CommandOutput<K,​V,​T> output)
      Create a new command with the supplied type.
      Parameters:
      type - Command type, must not be null.
      output - Command output, can be null.
    • 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 be null.
      output - Command output, can be null.
      args - Command args, can be null
  • Method Details

    • getOutput

      public CommandOutput<K,​V,​T> getOutput()
      Get the object that holds this command's output.
      Specified by:
      getOutput in interface RedisCommand<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 given exception.
      Specified by:
      completeExceptionally in interface RedisCommand<K,​V,​T>
      Parameters:
      throwable - the exception
      Returns:
      true if this invocation caused this CompletableFuture to transition to a completed state, else false
    • complete

      public void complete()
      Mark this command complete and notify all waiting threads.
      Specified by:
      complete in interface RedisCommand<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 interface RedisCommand<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 interface RedisCommand<K,​V,​T>
      Parameters:
      buf - Buffer to write to.
    • getError

      public String getError()
    • getArgs

      public CommandArgs<K,​V> getArgs()
      Specified by:
      getArgs in interface RedisCommand<K,​V,​T>
      Returns:
      the current command args.
    • get

      public T get()
      Returns:
      the resut from the output.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 interface RedisCommand<K,​V,​T>
      Parameters:
      output - the new command output
    • getType

      public ProtocolKeyword getType()
      Specified by:
      getType in interface RedisCommand<K,​V,​T>
      Returns:
      the Redis command type like SADD, HMSET, QUIT.
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: RedisCommand
      Returns true if this task was cancelled before it completed normally.
      Specified by:
      isCancelled in interface RedisCommand<K,​V,​T>
      Returns:
      true if the command was cancelled before it completed normally.
    • isDone

      public boolean isDone()
      Description copied from interface: RedisCommand
      Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation. In all of these cases, this method will return true.
      Specified by:
      isDone in interface RedisCommand<K,​V,​T>
      Returns:
      true if this task completed.