Package io.lettuce.core.pubsub
Class StatefulRedisPubSubConnectionImpl<K,V>
- 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:
AsyncCloseable
,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 oneStatefulRedisPubSubConnectionImpl
AConnectionWatchdog
monitors each connection and reconnects automatically untilRedisChannelHandler.close()
is called. All pending commands will be (re)sent after successful reconnection.- Author:
- Mark Paluch
-
-
Constructor Summary
Constructors Constructor Description StatefulRedisPubSubConnectionImpl(PubSubEndpoint<K,V> endpoint, RedisChannelWriter writer, RedisCodec<K,V> codec, Duration timeout)
Initialize a new connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activated()
Notification when the connection becomes active (connected).void
addListener(RedisPubSubListener<K,V> listener)
Add a new listener.RedisPubSubAsyncCommands<K,V>
async()
Returns theRedisAsyncCommands
API 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 theRedisReactiveCommands
API for the current connection.void
removeListener(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 theRedisCommands
API for the current connection.-
Methods inherited from class io.lettuce.core.StatefulRedisConnectionImpl
addListener, dispatch, dispatch, getCodec, getConnectionState, isMulti, preProcessCommand, removeListener, setClientName
-
Methods inherited from class io.lettuce.core.RedisChannelHandler
addListener, addListener, close, closeAsync, deactivated, flushCommands, getChannelWriter, getConnectionEvents, getOptions, getResources, getTimeout, isClosed, isOpen, registerCloseables, removeListener, reset, setAutoFlushCommands, setOptions, setTimeout, syncHandler
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.lettuce.core.api.StatefulConnection
addListener, close, closeAsync, dispatch, dispatch, flushCommands, getOptions, getResources, getTimeout, isOpen, removeListener, reset, setAutoFlushCommands, setTimeout
-
Methods inherited from interface io.lettuce.core.api.StatefulRedisConnection
addListener, isMulti, removeListener
-
-
-
-
Constructor Detail
-
StatefulRedisPubSubConnectionImpl
public StatefulRedisPubSubConnectionImpl(PubSubEndpoint<K,V> endpoint, RedisChannelWriter writer, RedisCodec<K,V> codec, Duration timeout)
Initialize a new connection.- Parameters:
endpoint
- thePubSubEndpoint
writer
- the writer used to write commandscodec
- Codec used to encode/decode keys and values.timeout
- Maximum time to wait for a response.
-
-
Method Detail
-
addListener
public void addListener(RedisPubSubListener<K,V> listener)
Add a new listener.- Specified by:
addListener
in interfaceStatefulRedisPubSubConnection<K,V>
- Parameters:
listener
- Listener.
-
removeListener
public void removeListener(RedisPubSubListener<K,V> listener)
Remove an existing listener.- Specified by:
removeListener
in interfaceStatefulRedisPubSubConnection<K,V>
- Parameters:
listener
- Listener.
-
async
public RedisPubSubAsyncCommands<K,V> async()
Description copied from interface:StatefulRedisConnection
Returns theRedisAsyncCommands
API for the current connection. Does not create a new connection.- Specified by:
async
in interfaceStatefulRedisConnection<K,V>
- Specified by:
async
in interfaceStatefulRedisPubSubConnection<K,V>
- Overrides:
async
in classStatefulRedisConnectionImpl<K,V>
- Returns:
- the asynchronous API for the underlying connection.
-
newRedisAsyncCommandsImpl
protected RedisPubSubAsyncCommandsImpl<K,V> newRedisAsyncCommandsImpl()
Description copied from class:StatefulRedisConnectionImpl
Create a new instance ofRedisAsyncCommandsImpl
. Can be overriden to extend.- Overrides:
newRedisAsyncCommandsImpl
in classStatefulRedisConnectionImpl<K,V>
- Returns:
- a new instance
-
sync
public RedisPubSubCommands<K,V> sync()
Description copied from interface:StatefulRedisConnection
Returns theRedisCommands
API for the current connection. Does not create a new connection.- Specified by:
sync
in interfaceStatefulRedisConnection<K,V>
- Specified by:
sync
in interfaceStatefulRedisPubSubConnection<K,V>
- Overrides:
sync
in classStatefulRedisConnectionImpl<K,V>
- Returns:
- the synchronous API for the underlying connection.
-
newRedisSyncCommandsImpl
protected RedisPubSubCommands<K,V> newRedisSyncCommandsImpl()
Description copied from class:StatefulRedisConnectionImpl
Create a new instance ofRedisCommands
. Can be overriden to extend.- Overrides:
newRedisSyncCommandsImpl
in classStatefulRedisConnectionImpl<K,V>
- Returns:
- a new instance
-
reactive
public RedisPubSubReactiveCommands<K,V> reactive()
Description copied from interface:StatefulRedisConnection
Returns theRedisReactiveCommands
API for the current connection. Does not create a new connection.- Specified by:
reactive
in interfaceStatefulRedisConnection<K,V>
- Specified by:
reactive
in interfaceStatefulRedisPubSubConnection<K,V>
- Overrides:
reactive
in classStatefulRedisConnectionImpl<K,V>
- Returns:
- the reactive API for the underlying connection.
-
newRedisReactiveCommandsImpl
protected RedisPubSubReactiveCommandsImpl<K,V> newRedisReactiveCommandsImpl()
Description copied from class:StatefulRedisConnectionImpl
Create a new instance ofRedisReactiveCommandsImpl
. Can be overriden to extend.- Overrides:
newRedisReactiveCommandsImpl
in classStatefulRedisConnectionImpl<K,V>
- Returns:
- a new instance
-
resubscribe
protected List<RedisFuture<Void>> 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:RedisChannelHandler
Notification when the connection becomes active (connected).- Specified by:
activated
in interfaceConnectionFacade
- Overrides:
activated
in classRedisChannelHandler<K,V>
-
-