- Type Parameters:
K- Key type.V- Value type.
- All Superinterfaces:
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
Modifier and Type Method Description voidclose()Close the connection.CompletableFuture<Void>closeAsync()Request to close the connection and return theCompletableFuturethat 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.voidflushCommands()Flush pending commands.ClientOptionsgetOptions()ClientResourcesgetResources()DurationgetTimeout()booleanisOpen()voidreset()Deprecated.since 5.2.voidsetAutoFlushCommands(boolean autoFlush)Disable or enable auto-flush behavior.voidsetTimeout(Duration timeout)Set the default command timeout for this connection.
-
Method Details
-
setTimeout
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
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
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:
closein interfaceAutoCloseable
-
closeAsync
CompletableFuture<Void> closeAsync()Request to close the connection and return theCompletableFuturethat is notified about its progress. The connection will become not usable anymore as soon as this method was called.- Specified by:
closeAsyncin interfaceAsyncCloseable- Returns:
- a
CompletableFuturethat 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.since 5.2. 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.
-