Package io.lettuce.core
Class CommandListenerWriter
- java.lang.Object
-
- io.lettuce.core.CommandListenerWriter
-
- All Implemented Interfaces:
AsyncCloseable
,AsyncCloseable
,RedisChannelWriter
,Closeable
,AutoCloseable
public class CommandListenerWriter extends Object implements RedisChannelWriter
Writer for command listeners.- Since:
- 6.1
- Author:
- Mikhael Sokolov, Mark Paluch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CommandListenerWriter.CommandListenerMulticaster
Wraps multiple command listeners into one multicaster.
-
Constructor Summary
Constructors Constructor Description CommandListenerWriter(RedisChannelWriter delegate, List<CommandListener> listeners)
-
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(List<CommandListener> commandListeners)
Check whether the list ofCommandListener
is not empty.void
reset()
Reset the command state.void
setAutoFlushCommands(boolean autoFlush)
Disable or enable auto-flush behavior.void
setConnectionFacade(ConnectionFacade connection)
Set the corresponding connection facade in order to notify it about channel active/inactive state.<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
-
CommandListenerWriter
public CommandListenerWriter(RedisChannelWriter delegate, List<CommandListener> listeners)
-
-
Method Detail
-
isSupported
public static boolean isSupported(List<CommandListener> commandListeners)
Check whether the list ofCommandListener
is not empty.- Parameters:
commandListeners
- must not benull
.- Returns:
true
if the list ofCommandListener
is not empty.
-
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
-
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
-
setConnectionFacade
public void setConnectionFacade(ConnectionFacade connection)
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:
connection
- the connection facade (external connection object)
-
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.
-
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
-
getClientResources
public ClientResources getClientResources()
- Specified by:
getClientResources
in interfaceRedisChannelWriter
- Returns:
- the
ClientResources
.
-
getDelegate
public RedisChannelWriter getDelegate()
-
-