Module lettuce.core

Class RedisStateMachine

java.lang.Object
io.lettuce.core.protocol.RedisStateMachine

public class RedisStateMachine
extends Object
State machine that decodes redis server responses encoded according to the Unified Request Protocol (RESP). Supports RESP2 and RESP3. Initialized with protocol discovery.
Author:
Will Glozer, Mark Paluch, Helly Guo
  • Constructor Details

    • RedisStateMachine

      public RedisStateMachine​(ByteBufAllocator alloc)
      Initialize a new instance.
  • Method Details

    • isDiscoverProtocol

      public boolean isDiscoverProtocol()
    • getProtocolVersion

      public ProtocolVersion getProtocolVersion()
    • setProtocolVersion

      public void setProtocolVersion​(ProtocolVersion protocolVersion)
    • decode

      public boolean decode​(ByteBuf buffer, CommandOutput<?,​?,​?> output)
      Decode a command using the input buffer.
      Parameters:
      buffer - Buffer containing data from the server.
      output - Current command output.
      Returns:
      true if a complete response was read.
    • decode

      public boolean decode​(ByteBuf buffer, CommandOutput<?,​?,​?> output, Consumer<Exception> errorHandler)
      Attempt to decode a redis response and return a flag indicating whether a complete response was read.
      Parameters:
      buffer - Buffer containing data from the server.
      output - Current command output.
      errorHandler - the error handler
      Returns:
      true if a complete response was read.
    • reset

      public void reset()
      Reset the state machine.
    • close

      public void close()
      Close the state machine to free resources.
    • safeSet

      protected void safeSet​(CommandOutput<?,​?,​?> output, boolean value, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.set(boolean). Completes a errorHandler exceptionally in case an exception occurs.
      Parameters:
      output -
      value -
      errorHandler -
    • safeSet

      protected void safeSet​(CommandOutput<?,​?,​?> output, long number, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.set(long). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      number -
      errorHandler -
    • safeSet

      protected void safeSet​(CommandOutput<?,​?,​?> output, double number, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.set(double). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      number -
      errorHandler -
    • safeSet

      protected void safeSet​(CommandOutput<?,​?,​?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.set(ByteBuffer). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      bytes -
      errorHandler -
    • safeSetSingle

      protected void safeSetSingle​(CommandOutput<?,​?,​?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.set(ByteBuffer). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      bytes -
      errorHandler -
    • safeSetBigNumber

      protected void safeSetBigNumber​(CommandOutput<?,​?,​?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.set(ByteBuffer). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      bytes -
      errorHandler -
    • safeMultiArray

      protected void safeMultiArray​(CommandOutput<?,​?,​?> output, int count, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.multiArray(int). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      count -
      errorHandler -
    • safeMultiPush

      protected void safeMultiPush​(CommandOutput<?,​?,​?> output, int count, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.multiPush(int). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      count -
      errorHandler -
    • safeMultiSet

      protected void safeMultiSet​(CommandOutput<?,​?,​?> output, int count, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.multiSet(int). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      count -
      errorHandler -
    • safeMultiMap

      protected void safeMultiMap​(CommandOutput<?,​?,​?> output, int count, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.multiMap(int). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      count -
      errorHandler -
    • safeSetError

      protected void safeSetError​(CommandOutput<?,​?,​?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
      Safely sets CommandOutput.setError(ByteBuffer). Notifies the errorHandler if an exception occurs.
      Parameters:
      output -
      bytes -
      errorHandler -