Module lettuce.core

Class CommandOutput<K,​V,​T>

java.lang.Object
io.lettuce.core.output.CommandOutput<K,​V,​T>
Type Parameters:
K - Key type.
V - Value type.
T - Output type.
Direct Known Subclasses:
BooleanListOutput, BooleanOutput, ByteArrayOutput, ClaimedMessagesOutput, DateOutput, DoubleListOutput, DoubleOutput, EnumSetOutput, GenericMapOutput, GeoCoordinatesListOutput, GeoCoordinatesValueListOutput, GeoWithinListOutput, IntegerListOutput, IntegerOutput, KeyListOutput, KeyOutput, KeyStreamingOutput, KeyValueListOutput, KeyValueOutput, KeyValueScoredValueOutput, KeyValueStreamingOutput, ListOfGenericMapsOutput, ListOfMapsOutput, MapOutput, MultiOutput, NestedMultiOutput, PendingMessageListOutput, PendingMessagesOutput, PubSubOutput, ReplayOutput, ScanOutput, ScoredValueListOutput, ScoredValueOutput, ScoredValueStreamingOutput, SocketAddressOutput, StatusOutput, StreamMessageListOutput, StreamReadOutput, StringListOutput, StringMatchResultOutput, StringValueListOutput, ValueListOutput, ValueOutput, ValueSetOutput, ValueStreamingOutput, ValueValueListOutput, VoidOutput

public abstract class CommandOutput<K,​V,​T>
extends Object
Base class for Redis command outputs.

Provides common decode methods and parsing functionality for output handling. Template methods that accept response values throw UnsupportedOperationException unless overridden by the concrete implementation.

Command outputs may accumulate their state until a command is finished or emit partial results during the decode process. Output implementations that wish to emit partial results can implement StreamingOutput push individual output elements to a StreamingOutput.Subscriber.

Author:
Will Glozer, Mark Paluch
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected RedisCodec<K,​V> codec  
    protected String error  
    protected T output  
  • Constructor Summary

    Constructors
    Constructor Description
    CommandOutput​(RedisCodec<K,​V> codec, T output)
    Initialize a new instance that encodes and decodes keys and values using the supplied codec.
  • Method Summary

    Modifier and Type Method Description
    void complete​(int depth)
    Mark the command output complete.
    protected String decodeAscii​(ByteBuffer bytes)  
    T get()
    Get the command output.
    String getError()
    Get the error that occurred.
    boolean hasError()
    Check if the command resulted in an error.
    void multi​(int count)
    Mark the beginning of a multi sequence (array).
    void multiArray​(int count)
    Mark the beginning of a multi sequence (array).
    void multiMap​(int count)
    Mark the beginning of a multi sequence (map).
    void multiPush​(int count)
    Mark the beginning of a multi sequence (push-array).
    void multiSet​(int count)
    Mark the beginning of a set.
    void set​(boolean value)
    Update the command output with a boolean.
    void set​(double number)
    Update the command output with a floating-point number.
    void set​(long integer)
    Update the command output with a 64-bit signed integer.
    void set​(ByteBuffer bytes)
    Update the command output with a sequence of bytes, or null.
    void setBigNumber​(ByteBuffer bytes)
    Update the command output with a big number.
    void setError​(String error)
    Set command output to an error message from the client.
    void setError​(ByteBuffer error)
    Set command output to an error message from the server.
    void setSingle​(ByteBuffer bytes)
    Update the command output with a sequence of bytes, or null representing a simple string.
    String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • codec

      protected final RedisCodec<K,​V> codec
    • output

      protected T output
    • error

      protected String error
  • Constructor Details

    • CommandOutput

      public CommandOutput​(RedisCodec<K,​V> codec, T output)
      Initialize a new instance that encodes and decodes keys and values using the supplied codec.
      Parameters:
      codec - Codec used to encode/decode keys and values, must not be null.
      output - Initial value of output.
  • Method Details

    • get

      public T get()
      Get the command output.
      Returns:
      The command output.
    • set

      public void set​(ByteBuffer bytes)
      Update the command output with a sequence of bytes, or null. Concrete CommandOutput implementations must override this method to decode bulk/bytes response values.
      Parameters:
      bytes - The command output, or null.
    • setSingle

      public void setSingle​(ByteBuffer bytes)
      Update the command output with a sequence of bytes, or null representing a simple string. Concrete CommandOutput implementations must override this method to decode single/bytes response values.
      Parameters:
      bytes - The command output, or null.
    • setBigNumber

      public void setBigNumber​(ByteBuffer bytes)
      Update the command output with a big number. Concrete CommandOutput implementations must override this method to decode big number response values.
      Parameters:
      bytes - The command output, or null.
      Since:
      6.0/RESP 3
    • set

      public void set​(long integer)
      Update the command output with a 64-bit signed integer. Concrete CommandOutput implementations must override this method to decode number (integer) response values.
      Parameters:
      integer - The command output.
    • set

      public void set​(double number)
      Update the command output with a floating-point number. Concrete CommandOutput implementations must override this method to decode double response values.
      Parameters:
      number - The command output.
      Since:
      6.0/RESP 3
    • set

      public void set​(boolean value)
      Update the command output with a boolean. Concrete CommandOutput implementations must override this method to decode boolean response values.
      Parameters:
      value - The command output.
      Since:
      6.0/RESP 3
    • setError

      public void setError​(ByteBuffer error)
      Set command output to an error message from the server.
      Parameters:
      error - Error message.
    • setError

      public void setError​(String error)
      Set command output to an error message from the client.
      Parameters:
      error - Error message.
    • hasError

      public boolean hasError()
      Check if the command resulted in an error.
      Returns:
      true if command resulted in an error.
    • getError

      public String getError()
      Get the error that occurred.
      Returns:
      The error.
    • complete

      public void complete​(int depth)
      Mark the command output complete.
      Parameters:
      depth - Remaining depth of output queue.
    • decodeAscii

      protected String decodeAscii​(ByteBuffer bytes)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • multi

      public void multi​(int count)
      Mark the beginning of a multi sequence (array).
      Parameters:
      count - expected number of elements in this multi sequence.
    • multiArray

      public void multiArray​(int count)
      Mark the beginning of a multi sequence (array).
      Parameters:
      count - expected number of elements in this multi sequence.
      Since:
      6.0/RESP 3
    • multiPush

      public void multiPush​(int count)
      Mark the beginning of a multi sequence (push-array).
      Parameters:
      count - expected number of elements in this multi sequence.
      Since:
      6.0/RESP 3
    • multiMap

      public void multiMap​(int count)
      Mark the beginning of a multi sequence (map).
      Parameters:
      count - expected number of elements in this multi sequence.
      Since:
      6.0/RESP 3
    • multiSet

      public void multiSet​(int count)
      Mark the beginning of a set.
      Parameters:
      count - expected number of elements in this multi sequence.
      Since:
      6.0/RESP 3