Package io.lettuce.core
Class RedisChannelHandler<K,V>
- java.lang.Object
-
- io.lettuce.core.RedisChannelHandler<K,V>
-
- Type Parameters:
K
- Key type.V
- Value type.
- All Implemented Interfaces:
ConnectionFacade
,Closeable
,AutoCloseable
- Direct Known Subclasses:
StatefulRedisClusterConnectionImpl
,StatefulRedisConnectionImpl
,StatefulRedisSentinelConnectionImpl
public abstract class RedisChannelHandler<K,V> extends Object implements Closeable, ConnectionFacade
Abstract base for every Redis connection. Provides basic connection functionality and tracks open resources.- Since:
- 3.0
- Author:
- Mark Paluch
-
-
Constructor Summary
Constructors Constructor Description RedisChannelHandler(RedisChannelWriter writer, Duration timeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
activated()
Notification when the connection becomes active (connected).protected void
addListener(io.lettuce.core.CloseEvents.CloseListener listener)
void
addListener(RedisConnectionStateListener listener)
Add a listener for theRedisConnectionStateListener
.void
close()
Close the connection (synchronous).CompletableFuture<Void>
closeAsync()
Close the connection (asynchronous).void
deactivated()
Notification when the connection becomes inactive (disconnected).protected <T> RedisCommand<K,V,T>
dispatch(RedisCommand<K,V,T> cmd)
protected Collection<RedisCommand<K,V,?>>
dispatch(Collection<? extends RedisCommand<K,V,?>> commands)
void
flushCommands()
RedisChannelWriter
getChannelWriter()
ConnectionEvents
getConnectionEvents()
ClientOptions
getOptions()
ClientResources
getResources()
Duration
getTimeout()
boolean
isClosed()
boolean
isOpen()
void
registerCloseables(Collection<Closeable> registry, Closeable... closeables)
Register Closeable resources.void
removeListener(RedisConnectionStateListener listener)
Removes a listener.void
reset()
Deprecated.void
setAutoFlushCommands(boolean autoFlush)
void
setOptions(ClientOptions clientOptions)
void
setTimeout(Duration timeout)
Set the command timeout for this connection.protected <T> T
syncHandler(Object asyncApi, Class<?>... interfaces)
-
-
-
Constructor Detail
-
RedisChannelHandler
public RedisChannelHandler(RedisChannelWriter writer, Duration timeout)
- Parameters:
writer
- the channel writertimeout
- timeout value
-
-
Method Detail
-
addListener
public void addListener(RedisConnectionStateListener listener)
Add a listener for theRedisConnectionStateListener
. The listener is notified every time a connect/disconnect/IO exception happens. The listener is called on the event loop thread so code within the listener methods must not block.- Parameters:
listener
- must not benull
.- Since:
- 6.2
-
removeListener
public void removeListener(RedisConnectionStateListener listener)
Removes a listener.- Parameters:
listener
- must not benull
.- Since:
- 6.2
-
setTimeout
public void setTimeout(Duration timeout)
Set the command timeout for this connection.- Parameters:
timeout
- Command timeout.- Since:
- 5.0
-
close
public void close()
Close the connection (synchronous).- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
closeAsync
public CompletableFuture<Void> closeAsync()
Close the connection (asynchronous).- Since:
- 5.1
-
dispatch
protected <T> RedisCommand<K,V,T> dispatch(RedisCommand<K,V,T> cmd)
-
dispatch
protected Collection<RedisCommand<K,V,?>> dispatch(Collection<? extends RedisCommand<K,V,?>> commands)
-
registerCloseables
public void registerCloseables(Collection<Closeable> registry, Closeable... closeables)
Register Closeable resources. Internal access only.- Parameters:
registry
- registry of closeablescloseables
- closeables to register
-
addListener
protected void addListener(io.lettuce.core.CloseEvents.CloseListener listener)
-
isClosed
public boolean isClosed()
- Returns:
- true if the connection is closed (final state in the connection lifecyle).
-
activated
public void activated()
Notification when the connection becomes active (connected).- Specified by:
activated
in interfaceConnectionFacade
-
deactivated
public void deactivated()
Notification when the connection becomes inactive (disconnected).- Specified by:
deactivated
in interfaceConnectionFacade
-
getChannelWriter
public RedisChannelWriter getChannelWriter()
- Returns:
- the channel writer
-
isOpen
public boolean isOpen()
- Returns:
- true if the connection is active and not closed.
-
reset
@Deprecated public void reset()
Deprecated.Description copied from interface:ConnectionFacade
Reset the connection state.- Specified by:
reset
in interfaceConnectionFacade
-
getConnectionEvents
public ConnectionEvents getConnectionEvents()
-
getOptions
public ClientOptions getOptions()
-
getResources
public ClientResources getResources()
-
setOptions
public void setOptions(ClientOptions clientOptions)
-
getTimeout
public Duration getTimeout()
-
setAutoFlushCommands
public void setAutoFlushCommands(boolean autoFlush)
-
flushCommands
public void flushCommands()
-
-