Module lettuce.core

Class AsyncCommand<K,​V,​T>

java.lang.Object
java.util.concurrent.CompletableFuture<T>
io.lettuce.core.protocol.AsyncCommand<K,​V,​T>
Type Parameters:
K - Key type.
V - Value type.
T - Command output type.
All Implemented Interfaces:
CompleteableCommand<T>, DecoratedCommand<K,​V,​T>, RedisCommand<K,​V,​T>, RedisFuture<T>, CompletionStage<T>, Future<T>
Direct Known Subclasses:
TransactionalCommand

public class AsyncCommand<K,​V,​T>
extends CompletableFuture<T>
implements RedisCommand<K,​V,​T>, RedisFuture<T>, CompleteableCommand<T>, DecoratedCommand<K,​V,​T>
An asynchronous redis command and its result. All successfully executed commands will eventually return a CommandOutput object.
Author:
Mark Paluch
  • Constructor Details

    • AsyncCommand

      public AsyncCommand​(RedisCommand<K,​V,​T> command)
      Parameters:
      command - the command, must not be null.
    • AsyncCommand

      protected AsyncCommand​(RedisCommand<K,​V,​T> command, int count)
      Parameters:
      command - the command, must not be null.
  • Method Details

    • await

      public boolean await​(long timeout, TimeUnit unit)
      Wait up to the specified time for the command output to become available.
      Specified by:
      await in interface RedisFuture<K>
      Parameters:
      timeout - Maximum time to wait for a result.
      unit - Unit of time for the timeout.
      Returns:
      true if the output became available.
    • 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.
    • complete

      public void complete()
      Mark this command complete and notify all waiting threads.
      Specified by:
      complete in interface RedisCommand<K,​V,​T>
    • completeResult

      protected void completeResult()
    • completeExceptionally

      public boolean completeExceptionally​(Throwable ex)
      Description copied from interface: RedisCommand
      Complete this command by attaching the given exception.
      Specified by:
      completeExceptionally in interface RedisCommand<K,​V,​T>
      Overrides:
      completeExceptionally in class CompletableFuture<T>
      Parameters:
      ex - the exception
      Returns:
      true if this invocation caused this CompletableFuture to transition to a completed state, else false
    • cancel

      public boolean cancel​(boolean mayInterruptIfRunning)
      Specified by:
      cancel in interface Future<K>
      Overrides:
      cancel in class CompletableFuture<T>
    • getError

      public String getError()
      Specified by:
      getError in interface RedisFuture<K>
      Returns:
      error text, if any error occurred.
    • getArgs

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

      public String toString()
      Overrides:
      toString in class CompletableFuture<T>
    • getType

      public ProtocolKeyword getType()
      Specified by:
      getType in interface RedisCommand<K,​V,​T>
      Returns:
      the Redis command type like SADD, HMSET, QUIT.
    • 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)
      Description copied from interface: RedisCommand
      Encode the command.
      Specified by:
      encode in interface RedisCommand<K,​V,​T>
      Parameters:
      buf - byte buffer to operate on.
    • 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
    • onComplete

      public void onComplete​(Consumer<? super T> action)
      Description copied from interface: CompleteableCommand
      Register a command callback for successive command completion that notifies the callback with the command result.
      Specified by:
      onComplete in interface CompleteableCommand<K>
      Parameters:
      action - must not be null.
    • onComplete

      public void onComplete​(BiConsumer<? super T,​Throwable> action)
      Description copied from interface: CompleteableCommand
      Register a command callback for command completion that notifies the callback with the command result or the failure resulting from command completion.
      Specified by:
      onComplete in interface CompleteableCommand<K>
      Parameters:
      action - must not be null.
    • getDelegate

      public RedisCommand<K,​V,​T> getDelegate()
      Description copied from interface: DecoratedCommand
      The underlying command.
      Specified by:
      getDelegate in interface DecoratedCommand<K,​V,​T>
      Returns:
      never null.
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object