java.lang.Object
io.lettuce.core.RedisChannelHandler<K,V>
io.lettuce.core.StatefulRedisConnectionImpl<K,V>
- Type Parameters:
K- Key type.V- Value type.
- All Implemented Interfaces:
StatefulConnection<K,V>,StatefulRedisConnection<K,V>,AsyncCloseable,ConnectionFacade,Closeable,AutoCloseable
- Direct Known Subclasses:
StatefulRedisPubSubConnectionImpl
public class StatefulRedisConnectionImpl<K,V> extends RedisChannelHandler<K,V> implements StatefulRedisConnection<K,V>
A thread-safe connection to a Redis server. Multiple threads may share one
StatefulRedisConnectionImpl
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
Fields Modifier and Type Field Description protected RedisAsyncCommandsImpl<K,V>asyncprotected RedisCodec<K,V>codecprotected MultiOutput<K,V>multiprotected RedisReactiveCommandsImpl<K,V>reactiveprotected RedisCommands<K,V>sync -
Constructor Summary
Constructors Constructor Description StatefulRedisConnectionImpl(RedisChannelWriter writer, PushHandler pushHandler, RedisCodec<K,V> codec, Duration timeout)Initialize a new connection. -
Method Summary
Modifier and Type Method Description voidaddListener(PushListener listener)Add a new listener.RedisAsyncCommands<K,V>async()Returns theRedisAsyncCommandsAPI for the current connection.<T> RedisCommand<K,V,T>dispatch(RedisCommand<K,V,T> command)Dispatch a command.Collection<RedisCommand<K,V,?>>dispatch(Collection<? extends RedisCommand<K,V,?>> commands)Dispatch multiple command in a single write on the channel.RedisCodec<K,V>getCodec()ConnectionStategetConnectionState()booleanisMulti()protected RedisAsyncCommandsImpl<K,V>newRedisAsyncCommandsImpl()Create a new instance ofRedisAsyncCommandsImpl.protected RedisReactiveCommandsImpl<K,V>newRedisReactiveCommandsImpl()Create a new instance ofRedisReactiveCommandsImpl.protected RedisCommands<K,V>newRedisSyncCommandsImpl()Create a new instance ofRedisCommands.protected <T> RedisCommand<K,V,T>preProcessCommand(RedisCommand<K,V,T> command)RedisReactiveCommands<K,V>reactive()Returns theRedisReactiveCommandsAPI for the current connection.voidremoveListener(PushListener listener)Remove an existing listener.voidsetClientName(String clientName)Deprecated.RedisCommands<K,V>sync()Returns theRedisCommandsAPI for the current connection.Methods inherited from class io.lettuce.core.RedisChannelHandler
activated, 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, flushCommands, getOptions, getResources, getTimeout, isOpen, reset, setAutoFlushCommands, setTimeout
-
Field Details
-
codec
-
sync
-
async
-
reactive
-
multi
-
-
Constructor Details
-
StatefulRedisConnectionImpl
public StatefulRedisConnectionImpl(RedisChannelWriter writer, PushHandler pushHandler, RedisCodec<K,V> codec, Duration timeout)Initialize a new connection.- Parameters:
writer- the channel writer.pushHandler- the handler for push notifications.codec- Codec used to encode/decode keys and values.timeout- Maximum time to wait for a response.
-
-
Method Details
-
getCodec
-
async
Description copied from interface:StatefulRedisConnectionReturns theRedisAsyncCommandsAPI for the current connection. Does not create a new connection.- Specified by:
asyncin interfaceStatefulRedisConnection<K,V>- Returns:
- the asynchronous API for the underlying connection.
-
newRedisSyncCommandsImpl
Create a new instance ofRedisCommands. Can be overriden to extend.- Returns:
- a new instance
-
newRedisAsyncCommandsImpl
Create a new instance ofRedisAsyncCommandsImpl. Can be overriden to extend.- 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>- Returns:
- the reactive API for the underlying connection.
-
newRedisReactiveCommandsImpl
Create a new instance ofRedisReactiveCommandsImpl. Can be overriden to extend.- 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>- Returns:
- the synchronous API for the underlying connection.
-
addListener
Add a new listener.- Specified by:
addListenerin interfaceStatefulRedisConnection<K,V>- Parameters:
listener- Listener.
-
removeListener
Remove an existing listener.- Specified by:
removeListenerin interfaceStatefulRedisConnection<K,V>- Parameters:
listener- Listener.
-
isMulti
public boolean isMulti()- Specified by:
isMultiin interfaceStatefulRedisConnection<K,V>- Returns:
- true, if the connection is within a transaction.
-
dispatch
Description copied from interface:StatefulConnectionDispatch a command. Write a command on the channel. The command may be changed/wrapped during write and the written instance is returned after the call. This command does not wait until the command completes and does not guarantee whether the command is executed successfully.- Specified by:
dispatchin interfaceStatefulConnection<K,V>- Overrides:
dispatchin classRedisChannelHandler<K,V>- Type Parameters:
T- result type- Parameters:
command- the Redis command.- Returns:
- the written Redis command.
-
dispatch
public Collection<RedisCommand<K,V,?>> dispatch(Collection<? extends RedisCommand<K,V,?>> commands)Description copied from interface:StatefulConnectionDispatch multiple command in a single write on the channel. The commands may be changed/wrapped during write and the written instance is returned after the call. This command does not wait until the command completes and does not guarantee whether the command is executed successfully.- Specified by:
dispatchin interfaceStatefulConnection<K,V>- Overrides:
dispatchin classRedisChannelHandler<K,V>- Parameters:
commands- the Redis commands.- Returns:
- the written Redis commands.
-
preProcessCommand
-
setClientName
Deprecated.since 6.0, useRedisServerAsyncCommands.clientSetname(Object).- Parameters:
clientName-
-
getConnectionState
-
RedisServerAsyncCommands.clientSetname(Object).