java.lang.Object
io.lettuce.core.RedisChannelHandler<K,V>
io.lettuce.core.StatefulRedisConnectionImpl<K,V>
io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl<K,V>
- Type Parameters:
K- Key type.V- Value type.
- All Implemented Interfaces:
StatefulConnection<K,V>,StatefulRedisConnection<K,V>,AsyncCloseable,ConnectionFacade,StatefulRedisPubSubConnection<K,V>,Closeable,AutoCloseable
public class StatefulRedisPubSubConnectionImpl<K,V> extends StatefulRedisConnectionImpl<K,V> implements StatefulRedisPubSubConnection<K,V>
An thread-safe pub/sub connection to a Redis server. Multiple threads may share one
StatefulRedisPubSubConnectionImpl
A ConnectionWatchdog monitors each connection and reconnects automatically until RedisChannelHandler.close() is called. All
pending commands will be (re)sent after successful reconnection.- Author:
- Mark Paluch
-
Field Summary
-
Constructor Summary
Constructors Constructor Description StatefulRedisPubSubConnectionImpl(PubSubEndpoint<K,V> endpoint, RedisChannelWriter writer, RedisCodec<K,V> codec, Duration timeout)Initialize a new connection. -
Method Summary
Modifier and Type Method Description voidactivated()Notification when the connection becomes active (connected).voidaddListener(RedisPubSubListener<K,V> listener)Add a new listener.RedisPubSubAsyncCommands<K,V>async()Returns theRedisAsyncCommandsAPI for the current connection.protected RedisPubSubAsyncCommandsImpl<K,V>newRedisAsyncCommandsImpl()Create a new instance ofRedisAsyncCommandsImpl.protected RedisPubSubReactiveCommandsImpl<K,V>newRedisReactiveCommandsImpl()Create a new instance ofRedisReactiveCommandsImpl.protected RedisPubSubCommands<K,V>newRedisSyncCommandsImpl()Create a new instance ofRedisCommands.RedisPubSubReactiveCommands<K,V>reactive()Returns theRedisReactiveCommandsAPI for the current connection.voidremoveListener(RedisPubSubListener<K,V> listener)Remove an existing listener.protected List<RedisFuture<Void>>resubscribe()Re-subscribe to all previously subscribed channels and patterns.RedisPubSubCommands<K,V>sync()Returns theRedisCommandsAPI for the current connection.Methods inherited from class io.lettuce.core.StatefulRedisConnectionImpl
addListener, dispatch, dispatch, getCodec, getConnectionState, isMulti, preProcessCommand, removeListener, setClientNameMethods inherited from class io.lettuce.core.RedisChannelHandler
addListener, close, closeAsync, deactivated, flushCommands, getChannelWriter, getOptions, getResources, getTimeout, isClosed, isOpen, registerCloseables, reset, setAutoFlushCommands, setOptions, setTimeout, syncHandlerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.lettuce.core.api.StatefulConnection
close, closeAsync, dispatch, dispatch, flushCommands, getOptions, getResources, getTimeout, isOpen, reset, setAutoFlushCommands, setTimeoutMethods inherited from interface io.lettuce.core.api.StatefulRedisConnection
addListener, isMulti, removeListener
-
Constructor Details
-
StatefulRedisPubSubConnectionImpl
public StatefulRedisPubSubConnectionImpl(PubSubEndpoint<K,V> endpoint, RedisChannelWriter writer, RedisCodec<K,V> codec, Duration timeout)Initialize a new connection.- Parameters:
endpoint- thePubSubEndpointwriter- the writer used to write commandscodec- Codec used to encode/decode keys and values.timeout- Maximum time to wait for a response.
-
-
Method Details
-
addListener
Add a new listener.- Specified by:
addListenerin interfaceStatefulRedisPubSubConnection<K,V>- Parameters:
listener- Listener.
-
removeListener
Remove an existing listener.- Specified by:
removeListenerin interfaceStatefulRedisPubSubConnection<K,V>- Parameters:
listener- Listener.
-
async
Description copied from interface:StatefulRedisConnectionReturns theRedisAsyncCommandsAPI for the current connection. Does not create a new connection.- Specified by:
asyncin interfaceStatefulRedisConnection<K,V>- Specified by:
asyncin interfaceStatefulRedisPubSubConnection<K,V>- Overrides:
asyncin classStatefulRedisConnectionImpl<K,V>- Returns:
- the asynchronous API for the underlying connection.
-
newRedisAsyncCommandsImpl
Description copied from class:StatefulRedisConnectionImplCreate a new instance ofRedisAsyncCommandsImpl. Can be overriden to extend.- Overrides:
newRedisAsyncCommandsImplin classStatefulRedisConnectionImpl<K,V>- Returns:
- a new instance
-
sync
Description copied from interface:StatefulRedisConnectionReturns theRedisCommandsAPI for the current connection. Does not create a new connection.- Specified by:
syncin interfaceStatefulRedisConnection<K,V>- Specified by:
syncin interfaceStatefulRedisPubSubConnection<K,V>- Overrides:
syncin classStatefulRedisConnectionImpl<K,V>- Returns:
- the synchronous API for the underlying connection.
-
newRedisSyncCommandsImpl
Description copied from class:StatefulRedisConnectionImplCreate a new instance ofRedisCommands. Can be overriden to extend.- Overrides:
newRedisSyncCommandsImplin classStatefulRedisConnectionImpl<K,V>- Returns:
- a new instance
-
reactive
Description copied from interface:StatefulRedisConnectionReturns theRedisReactiveCommandsAPI for the current connection. Does not create a new connection.- Specified by:
reactivein interfaceStatefulRedisConnection<K,V>- Specified by:
reactivein interfaceStatefulRedisPubSubConnection<K,V>- Overrides:
reactivein classStatefulRedisConnectionImpl<K,V>- Returns:
- the reactive API for the underlying connection.
-
newRedisReactiveCommandsImpl
Description copied from class:StatefulRedisConnectionImplCreate a new instance ofRedisReactiveCommandsImpl. Can be overriden to extend.- Overrides:
newRedisReactiveCommandsImplin classStatefulRedisConnectionImpl<K,V>- Returns:
- a new instance
-
resubscribe
Re-subscribe to all previously subscribed channels and patterns.- Returns:
- list of the futures of the subscribe and psubscribe commands.
-
activated
public void activated()Description copied from class:RedisChannelHandlerNotification when the connection becomes active (connected).- Specified by:
activatedin interfaceConnectionFacade- Overrides:
activatedin classRedisChannelHandler<K,V>
-