Package io.lettuce.core.api
Interface StatefulConnection<K,V>
-
- Type Parameters:
K
- Key type.V
- Value type.
- All Superinterfaces:
AsyncCloseable
,AsyncCloseable
,AutoCloseable
- All Known Subinterfaces:
StatefulRedisClusterConnection<K,V>
,StatefulRedisClusterPubSubConnection<K,V>
,StatefulRedisConnection<K,V>
,StatefulRedisMasterReplicaConnection<K,V>
,StatefulRedisMasterSlaveConnection<K,V>
,StatefulRedisPubSubConnection<K,V>
,StatefulRedisSentinelConnection<K,V>
- All Known Implementing Classes:
StatefulRedisClusterConnectionImpl
,StatefulRedisConnectionImpl
,StatefulRedisPubSubConnectionImpl
,StatefulRedisSentinelConnectionImpl
public interface StatefulConnection<K,V> extends AutoCloseable, AsyncCloseable
A stateful connection providing command dispatching, timeouts and open/close methods.- Since:
- 4.0
- Author:
- Mark Paluch
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addListener(RedisConnectionStateListener listener)
Add a listener for theRedisConnectionStateListener
.void
close()
Close the connection.CompletableFuture<Void>
closeAsync()
Request to close the connection and return theCompletableFuture
that is notified about its progress.<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.void
flushCommands()
Flush pending commands.ClientOptions
getOptions()
ClientResources
getResources()
Duration
getTimeout()
boolean
isOpen()
void
removeListener(RedisConnectionStateListener listener)
Removes a listener.void
reset()
Deprecated.since 5.2.void
setAutoFlushCommands(boolean autoFlush)
Disable or enable auto-flush behavior.void
setTimeout(Duration timeout)
Set the default command timeout for this connection.
-
-
-
Method Detail
-
addListener
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
void removeListener(RedisConnectionStateListener listener)
Removes a listener.- Parameters:
listener
- must not benull
.- Since:
- 6.2
-
setTimeout
void setTimeout(Duration timeout)
Set the default command timeout for this connection. A zero timeout value indicates to not time out.- Parameters:
timeout
- Command timeout.- Since:
- 5.0
-
getTimeout
Duration getTimeout()
- Returns:
- the timeout.
-
dispatch
<T> RedisCommand<K,V,T> dispatch(RedisCommand<K,V,T> command)
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.- Type Parameters:
T
- result type- Parameters:
command
- the Redis command.- Returns:
- the written Redis command.
-
dispatch
Collection<RedisCommand<K,V,?>> dispatch(Collection<? extends RedisCommand<K,V,?>> commands)
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.- Parameters:
commands
- the Redis commands.- Returns:
- the written Redis commands.
- Since:
- 5.0
-
close
void close()
Close the connection. The connection will become not usable anymore as soon as this method was called.- Specified by:
close
in interfaceAutoCloseable
-
closeAsync
CompletableFuture<Void> closeAsync()
Request to close the connection and return theCompletableFuture
that is notified about its progress. The connection will become not usable anymore as soon as this method was called.- Specified by:
closeAsync
in interfaceAsyncCloseable
- Specified by:
closeAsync
in interfaceAsyncCloseable
- Returns:
- a
CompletableFuture
that is notified once the operation completes, either because the operation was successful or because of an error. - Since:
- 5.1
-
isOpen
boolean isOpen()
- Returns:
- true if the connection is open (connected and not closed).
-
getOptions
ClientOptions getOptions()
- Returns:
- the client options valid for this connection.
-
getResources
ClientResources getResources()
- Returns:
- the client resources used for this connection.
-
reset
@Deprecated void reset()
Deprecated.since 5.2. To be removed with 7.0. This method is unsafe and can cause protocol offsets (i.e. Redis commands are completed with previous command values).Reset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the internal state machine gets out of sync with the connection (e.g. errors during external SSL tunneling). Calling this method will reset the protocol state, therefore it is considered unsafe.
-
setAutoFlushCommands
void setAutoFlushCommands(boolean autoFlush)
Disable or enable auto-flush behavior. Default istrue
. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until aflushCommands()
is issued. After callingflushCommands()
commands are sent to the transport and executed by Redis.- Parameters:
autoFlush
- state of autoFlush.
-
flushCommands
void flushCommands()
Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to achieve batching. No-op if channel is not connected.
-
-