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 Summary
Constructors Constructor Description RedisStateMachine(ByteBufAllocator alloc)Initialize a new instance. -
Method Summary
Modifier and Type Method Description voidclose()Close the state machine to free resources.booleandecode(ByteBuf buffer, CommandOutput<?,?,?> output)Decode a command using the input buffer.booleandecode(ByteBuf buffer, CommandOutput<?,?,?> output, Consumer<Exception> errorHandler)Attempt to decode a redis response and return a flag indicating whether a complete response was read.ProtocolVersiongetProtocolVersion()booleanisDiscoverProtocol()voidreset()Reset the state machine.protected voidsafeMultiArray(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiArray(int).protected voidsafeMultiMap(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiMap(int).protected voidsafeMultiPush(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiPush(int).protected voidsafeMultiSet(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiSet(int).protected voidsafeSet(CommandOutput<?,?,?> output, boolean value, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(boolean).protected voidsafeSet(CommandOutput<?,?,?> output, double number, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(double).protected voidsafeSet(CommandOutput<?,?,?> output, long number, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(long).protected voidsafeSet(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(ByteBuffer).protected voidsafeSetBigNumber(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(ByteBuffer).protected voidsafeSetError(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.setError(ByteBuffer).protected voidsafeSetSingle(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(ByteBuffer).voidsetProtocolVersion(ProtocolVersion protocolVersion)
-
Constructor Details
-
RedisStateMachine
Initialize a new instance.
-
-
Method Details
-
isDiscoverProtocol
public boolean isDiscoverProtocol() -
getProtocolVersion
-
setProtocolVersion
-
decode
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 setsCommandOutput.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 setsCommandOutput.set(long). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-number-errorHandler-
-
safeSet
protected void safeSet(CommandOutput<?,?,?> output, double number, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(double). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-number-errorHandler-
-
safeSet
protected void safeSet(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(ByteBuffer). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-bytes-errorHandler-
-
safeSetSingle
protected void safeSetSingle(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(ByteBuffer). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-bytes-errorHandler-
-
safeSetBigNumber
protected void safeSetBigNumber(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.set(ByteBuffer). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-bytes-errorHandler-
-
safeMultiArray
protected void safeMultiArray(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiArray(int). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-count-errorHandler-
-
safeMultiPush
protected void safeMultiPush(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiPush(int). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-count-errorHandler-
-
safeMultiSet
protected void safeMultiSet(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiSet(int). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-count-errorHandler-
-
safeMultiMap
protected void safeMultiMap(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)Safely setsCommandOutput.multiMap(int). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-count-errorHandler-
-
safeSetError
protected void safeSetError(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)Safely setsCommandOutput.setError(ByteBuffer). Notifies theerrorHandlerif an exception occurs.- Parameters:
output-bytes-errorHandler-
-