Package io.lettuce.core
Class StatefulRedisConnectionImpl<K,V>
- 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:
AsyncCloseable
,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 oneStatefulRedisConnectionImpl
AConnectionWatchdog
monitors each connection and reconnects automatically untilRedisChannelHandler.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>
async
protected RedisCodec<K,V>
codec
protected MultiOutput<K,V>
multi
protected RedisReactiveCommandsImpl<K,V>
reactive
protected 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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addListener(PushListener listener)
Add a new listener.RedisAsyncCommands<K,V>
async()
Returns theRedisAsyncCommands
API 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()
ConnectionState
getConnectionState()
boolean
isMulti()
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 theRedisReactiveCommands
API for the current connection.void
removeListener(PushListener listener)
Remove an existing listener.void
setClientName(String clientName)
Deprecated.since 6.0, useRedisServerAsyncCommands.clientSetname(Object)
.RedisCommands<K,V>
sync()
Returns theRedisCommands
API for the current connection.-
Methods inherited from class io.lettuce.core.RedisChannelHandler
activated, 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, flushCommands, getOptions, getResources, getTimeout, isOpen, removeListener, reset, setAutoFlushCommands, setTimeout
-
-
-
-
Field Detail
-
codec
protected final RedisCodec<K,V> codec
-
sync
protected final RedisCommands<K,V> sync
-
async
protected final RedisAsyncCommandsImpl<K,V> async
-
reactive
protected final RedisReactiveCommandsImpl<K,V> reactive
-
multi
protected MultiOutput<K,V> multi
-
-
Constructor Detail
-
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 Detail
-
getCodec
public RedisCodec<K,V> getCodec()
-
async
public RedisAsyncCommands<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>
- Returns:
- the asynchronous API for the underlying connection.
-
newRedisSyncCommandsImpl
protected RedisCommands<K,V> newRedisSyncCommandsImpl()
Create a new instance ofRedisCommands
. Can be overriden to extend.- Returns:
- a new instance
-
newRedisAsyncCommandsImpl
protected RedisAsyncCommandsImpl<K,V> newRedisAsyncCommandsImpl()
Create a new instance ofRedisAsyncCommandsImpl
. Can be overriden to extend.- Returns:
- a new instance
-
reactive
public RedisReactiveCommands<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>
- Returns:
- the reactive API for the underlying connection.
-
newRedisReactiveCommandsImpl
protected RedisReactiveCommandsImpl<K,V> newRedisReactiveCommandsImpl()
Create a new instance ofRedisReactiveCommandsImpl
. Can be overriden to extend.- Returns:
- a new instance
-
sync
public RedisCommands<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>
- Returns:
- the synchronous API for the underlying connection.
-
addListener
public void addListener(PushListener listener)
Add a new listener.- Specified by:
addListener
in interfaceStatefulRedisConnection<K,V>
- Parameters:
listener
- Listener.
-
removeListener
public void removeListener(PushListener listener)
Remove an existing listener.- Specified by:
removeListener
in interfaceStatefulRedisConnection<K,V>
- Parameters:
listener
- Listener.
-
isMulti
public boolean isMulti()
- Specified by:
isMulti
in interfaceStatefulRedisConnection<K,V>
- Returns:
- true, if the connection is within a transaction.
-
dispatch
public <T> RedisCommand<K,V,T> dispatch(RedisCommand<K,V,T> command)
Description copied from interface:StatefulConnection
Dispatch 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:
dispatch
in interfaceStatefulConnection<K,V>
- Overrides:
dispatch
in 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:StatefulConnection
Dispatch 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:
dispatch
in interfaceStatefulConnection<K,V>
- Overrides:
dispatch
in classRedisChannelHandler<K,V>
- Parameters:
commands
- the Redis commands.- Returns:
- the written Redis commands.
-
preProcessCommand
protected <T> RedisCommand<K,V,T> preProcessCommand(RedisCommand<K,V,T> command)
-
setClientName
@Deprecated public void setClientName(String clientName)
Deprecated.since 6.0, useRedisServerAsyncCommands.clientSetname(Object)
.- Parameters:
clientName
-
-
getConnectionState
public ConnectionState getConnectionState()
-
-