Module lettuce.core

Interface StatefulConnection<K,​V>

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 Details

    • 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 interface AutoCloseable
    • closeAsync

      CompletableFuture<Void> closeAsync()
      Request to close the connection and return the CompletableFuture that is notified about its progress. The connection will become not usable anymore as soon as this method was called.
      Specified by:
      closeAsync in interface AsyncCloseable
      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. 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 is true. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until a flushCommands() is issued. After calling flushCommands() 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.