java.lang.Object
io.lettuce.core.protocol.CommandExpiryWriter
- All Implemented Interfaces:
AsyncCloseable,RedisChannelWriter,Closeable,AutoCloseable
public class CommandExpiryWriter extends Object implements RedisChannelWriter
Extension to
RedisChannelWriter that expires commands. Command timeout starts at the time the command is written
regardless to flushing mode (user-controlled batching).- Since:
- 5.1
- Author:
- Mark Paluch
- See Also:
TimeoutOptions
-
Constructor Summary
Constructors Constructor Description CommandExpiryWriter(RedisChannelWriter writer, ClientOptions clientOptions, ClientResources clientResources)Create a newCommandExpiryWriter. -
Method Summary
Modifier and Type Method Description voidclose()CompletableFuture<Void>closeAsync()Asynchronously close theRedisChannelWriter.voidflushCommands()Flush pending commands.ClientResourcesgetClientResources()static booleanisSupported(ClientOptions clientOptions)Check whetherClientOptionsis configured to timeout commands.voidreset()Reset the command state.voidsetAutoFlushCommands(boolean autoFlush)Disable or enable auto-flush behavior.voidsetConnectionFacade(ConnectionFacade connectionFacade)Set the corresponding connection facade in order to notify it about channel active/inactive state.voidsetTimeout(Duration timeout)<K, V, T> RedisCommand<K,V,T>write(RedisCommand<K,V,T> command)Write a command on the channel.<K, V> Collection<RedisCommand<K,V,?>>write(Collection<? extends RedisCommand<K,V,?>> redisCommands)Write multiple commands on the channel.
-
Constructor Details
-
CommandExpiryWriter
public CommandExpiryWriter(RedisChannelWriter writer, ClientOptions clientOptions, ClientResources clientResources)Create a newCommandExpiryWriter.- Parameters:
writer- must not benull.clientOptions- must not benull.clientResources- must not benull.
-
-
Method Details
-
isSupported
Check whetherClientOptionsis configured to timeout commands.- Parameters:
clientOptions- must not benull.- Returns:
trueifClientOptionsare configured to timeout commands.
-
setConnectionFacade
Description copied from interface:RedisChannelWriterSet the corresponding connection facade in order to notify it about channel active/inactive state.- Specified by:
setConnectionFacadein interfaceRedisChannelWriter- Parameters:
connectionFacade- the connection facade (external connection object)
-
getClientResources
- Specified by:
getClientResourcesin interfaceRedisChannelWriter- Returns:
- the
ClientResources.
-
setAutoFlushCommands
public void setAutoFlushCommands(boolean autoFlush)Description copied from interface:RedisChannelWriterDisable or enable auto-flush behavior. Default istrue. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until aRedisChannelWriter.flushCommands()is issued. After callingRedisChannelWriter.flushCommands()commands are sent to the transport and executed by Redis.- Specified by:
setAutoFlushCommandsin interfaceRedisChannelWriter- Parameters:
autoFlush- state of autoFlush.
-
write
Description copied from interface:RedisChannelWriterWrite a command on the channel. The command may be changed/wrapped during write and the written instance is returned after the call.- Specified by:
writein interfaceRedisChannelWriterT- result type- Parameters:
command- the Redis command.- Returns:
- the written Redis command.
-
write
public <K, V> Collection<RedisCommand<K,V,?>> write(Collection<? extends RedisCommand<K,V,?>> redisCommands)Description copied from interface:RedisChannelWriterWrite multiple commands on the channel. The commands may be changed/wrapped during write and the written instance is returned after the call.- Specified by:
writein interfaceRedisChannelWriter- Type Parameters:
K- key typeV- value type- Parameters:
redisCommands- the Redis commands.- Returns:
- the written redis command
-
flushCommands
public void flushCommands()Description copied from interface:RedisChannelWriterFlush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to achieve batching. No-op if channel is not connected.- Specified by:
flushCommandsin interfaceRedisChannelWriter
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRedisChannelWriter
-
closeAsync
Description copied from interface:RedisChannelWriterAsynchronously close theRedisChannelWriter.- Specified by:
closeAsyncin interfaceAsyncCloseable- Specified by:
closeAsyncin interfaceRedisChannelWriter- Returns:
- future for result synchronization.
-
reset
public void reset()Description copied from interface:RedisChannelWriterReset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the internal state machine gets out of sync with the connection (e.g. errors during external SSL tunneling). Calling this method will reset the protocol state, therefore it is considered unsafe.- Specified by:
resetin interfaceRedisChannelWriter
-
setTimeout
-