Package io.lettuce.core.protocol
Class CommandExpiryWriter
- java.lang.Object
-
- io.lettuce.core.protocol.CommandExpiryWriter
-
- All Implemented Interfaces:
AsyncCloseable
,AsyncCloseable
,RedisChannelWriter
,Closeable
,AutoCloseable
public class CommandExpiryWriter extends Object implements RedisChannelWriter
Extension toRedisChannelWriter
that expires commands. Command timeout starts at the time the command is written regardless toflushing mode
(user-controlled batching).- Since:
- 5.1
- Author:
- Mark Paluch, Tianyi Yang
- See Also:
TimeoutOptions
-
-
Constructor Summary
Constructors Constructor Description CommandExpiryWriter(RedisChannelWriter delegate, ClientOptions clientOptions, ClientResources clientResources)
Create a newCommandExpiryWriter
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
CompletableFuture<Void>
closeAsync()
Asynchronously close theRedisChannelWriter
.void
flushCommands()
Flush pending commands.ClientResources
getClientResources()
RedisChannelWriter
getDelegate()
static boolean
isSupported(ClientOptions clientOptions)
Check whetherClientOptions
is configured to timeout commands.void
reset()
Reset the command state.void
setAutoFlushCommands(boolean autoFlush)
Disable or enable auto-flush behavior.void
setConnectionFacade(ConnectionFacade connectionFacade)
Set the corresponding connection facade in order to notify it about channel active/inactive state.void
setTimeout(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 Detail
-
CommandExpiryWriter
public CommandExpiryWriter(RedisChannelWriter delegate, ClientOptions clientOptions, ClientResources clientResources)
Create a newCommandExpiryWriter
.- Parameters:
delegate
- must not benull
.clientOptions
- must not benull
.clientResources
- must not benull
.
-
-
Method Detail
-
isSupported
public static boolean isSupported(ClientOptions clientOptions)
Check whetherClientOptions
is configured to timeout commands.- Parameters:
clientOptions
- must not benull
.- Returns:
true
ifClientOptions
are configured to timeout commands.
-
setConnectionFacade
public void setConnectionFacade(ConnectionFacade connectionFacade)
Description copied from interface:RedisChannelWriter
Set the corresponding connection facade in order to notify it about channel active/inactive state.- Specified by:
setConnectionFacade
in interfaceRedisChannelWriter
- Parameters:
connectionFacade
- the connection facade (external connection object)
-
getClientResources
public ClientResources getClientResources()
- Specified by:
getClientResources
in interfaceRedisChannelWriter
- Returns:
- the
ClientResources
.
-
setAutoFlushCommands
public void setAutoFlushCommands(boolean autoFlush)
Description copied from interface:RedisChannelWriter
Disable 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:
setAutoFlushCommands
in interfaceRedisChannelWriter
- Parameters:
autoFlush
- state of autoFlush.
-
write
public <K,V,T> RedisCommand<K,V,T> write(RedisCommand<K,V,T> command)
Description copied from interface:RedisChannelWriter
Write a command on the channel. The command may be changed/wrapped during write and the written instance is returned after the call.- Specified by:
write
in interfaceRedisChannelWriter
T
- 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:RedisChannelWriter
Write multiple commands on the channel. The commands may be changed/wrapped during write and the written instance is returned after the call.- Specified by:
write
in 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:RedisChannelWriter
Flush 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:
flushCommands
in interfaceRedisChannelWriter
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceRedisChannelWriter
-
closeAsync
public CompletableFuture<Void> closeAsync()
Description copied from interface:RedisChannelWriter
Asynchronously close theRedisChannelWriter
.- Specified by:
closeAsync
in interfaceAsyncCloseable
- Specified by:
closeAsync
in interfaceAsyncCloseable
- Specified by:
closeAsync
in interfaceRedisChannelWriter
- Returns:
- future for result synchronization.
-
reset
public void reset()
Description copied from interface:RedisChannelWriter
Reset 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:
reset
in interfaceRedisChannelWriter
-
setTimeout
public void setTimeout(Duration timeout)
-
getDelegate
public RedisChannelWriter getDelegate()
-
-