Package io.lettuce.core.protocol
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, shikharid
-
-
Constructor Summary
Constructors Constructor Description RedisStateMachine()
Initialize a new instance.RedisStateMachine(ByteBufAllocator alloc)
Deprecated.since 6.3,no longer required
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the state machine to free resources.boolean
decode(ByteBuf buffer, CommandOutput<?,?,?> output)
Decode a command using the input buffer.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.ProtocolVersion
getProtocolVersion()
boolean
isDiscoverProtocol()
void
reset()
Reset the state machine.protected void
safeMultiArray(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiArray(int)
.protected void
safeMultiMap(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiMap(int)
.protected void
safeMultiPush(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiPush(int)
.protected void
safeMultiSet(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiSet(int)
.protected void
safeSet(CommandOutput<?,?,?> output, boolean value, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(boolean)
.protected void
safeSet(CommandOutput<?,?,?> output, double number, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(double)
.protected void
safeSet(CommandOutput<?,?,?> output, long number, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(long)
.protected void
safeSet(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(ByteBuffer)
.protected void
safeSetBigNumber(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(ByteBuffer)
.protected void
safeSetError(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.setError(ByteBuffer)
.protected void
safeSetSingle(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(ByteBuffer)
.void
setProtocolVersion(ProtocolVersion protocolVersion)
-
-
-
Constructor Detail
-
RedisStateMachine
@Deprecated public RedisStateMachine(ByteBufAllocator alloc)
Deprecated.since 6.3,no longer required
.Initialize a new instance.
-
RedisStateMachine
public RedisStateMachine()
Initialize a new instance.
-
-
Method Detail
-
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 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 theerrorHandler
if an exception occurs.- Parameters:
output
-number
-errorHandler
-
-
safeSet
protected void safeSet(CommandOutput<?,?,?> output, double number, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(double)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-number
-errorHandler
-
-
safeSet
protected void safeSet(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(ByteBuffer)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-bytes
-errorHandler
-
-
safeSetSingle
protected void safeSetSingle(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(ByteBuffer)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-bytes
-errorHandler
-
-
safeSetBigNumber
protected void safeSetBigNumber(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.set(ByteBuffer)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-bytes
-errorHandler
-
-
safeMultiArray
protected void safeMultiArray(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiArray(int)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-count
-errorHandler
-
-
safeMultiPush
protected void safeMultiPush(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiPush(int)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-count
-errorHandler
-
-
safeMultiSet
protected void safeMultiSet(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiSet(int)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-count
-errorHandler
-
-
safeMultiMap
protected void safeMultiMap(CommandOutput<?,?,?> output, int count, Consumer<Exception> errorHandler)
Safely setsCommandOutput.multiMap(int)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-count
-errorHandler
-
-
safeSetError
protected void safeSetError(CommandOutput<?,?,?> output, ByteBuffer bytes, Consumer<Exception> errorHandler)
Safely setsCommandOutput.setError(ByteBuffer)
. Notifies theerrorHandler
if an exception occurs.- Parameters:
output
-bytes
-errorHandler
-
-
-