Class RedisDecoder

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler

@UnstableApi public final class RedisDecoder extends ByteToMessageDecoder
Decodes the Redis protocol into RedisMessage objects following RESP (REdis Serialization Protocol). RedisMessage parts can be aggregated to RedisMessage using RedisArrayAggregator or processed directly.
  • Field Details

  • Constructor Details

    • RedisDecoder

      public RedisDecoder()
      Creates a new instance with default maxInlineMessageLength and messagePool and inline command decoding disabled.
    • RedisDecoder

      public RedisDecoder(boolean decodeInlineCommands)
      Creates a new instance with default maxInlineMessageLength and messagePool.
      Parameters:
      decodeInlineCommands - if true, inline commands will be decoded.
    • RedisDecoder

      public RedisDecoder(int maxInlineMessageLength, RedisMessagePool messagePool)
      Creates a new instance with inline command decoding disabled.
      Parameters:
      maxInlineMessageLength - the maximum length of inline message.
      messagePool - the predefined message pool.
    • RedisDecoder

      public RedisDecoder(int maxInlineMessageLength, RedisMessagePool messagePool, boolean decodeInlineCommands)
      Creates a new instance.
      Parameters:
      maxInlineMessageLength - the maximum length of inline message.
      messagePool - the predefined message pool.
      decodeInlineCommands - if true, inline commands will be decoded.
  • Method Details

    • decode

      protected void decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
      Description copied from class: ByteToMessageDecoder
      Decode the from one ByteBuf to an other. This method will be called till either the input ByteBuf has nothing to read when return from this method or till nothing was read from the input ByteBuf.
      Specified by:
      decode in class ByteToMessageDecoder
      Parameters:
      ctx - the ChannelHandlerContext which this ByteToMessageDecoder belongs to
      in - the ByteBuf from which to read data
      out - the List to which decoded messages should be added
      Throws:
      java.lang.Exception - is thrown if an error occurs
    • resetDecoder

      private void resetDecoder()
    • decodeType

      private boolean decodeType(ByteBuf in) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • decodeInline

      private boolean decodeInline(ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • decodeLength

      private boolean decodeLength(ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • decodeBulkString

      private boolean decodeBulkString(ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • decodeBulkStringEndOfLine

      private boolean decodeBulkStringEndOfLine(ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • decodeBulkStringContent

      private boolean decodeBulkStringContent(ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • readEndOfLine

      private static void readEndOfLine(ByteBuf in)
    • newInlineRedisMessage

      private RedisMessage newInlineRedisMessage(RedisMessageType messageType, ByteBuf content)
    • readLine

      private static ByteBuf readLine(ByteBuf in)
    • parseRedisNumber

      private long parseRedisNumber(ByteBuf byteBuf)
    • parsePositiveNumber

      private long parsePositiveNumber(ByteBuf byteBuf)