Interface RedisConnection

All Superinterfaces:
AutoCloseable, DefaultedRedisConnection, RedisCommands, RedisCommandsProvider, RedisConnectionCommands, RedisGeoCommands, RedisHashCommands, RedisHyperLogLogCommands, RedisKeyCommands, RedisListCommands, RedisPubSubCommands, RedisScriptingCommands, RedisServerCommands, RedisSetCommands, RedisStreamCommands, RedisStringCommands, RedisTxCommands, RedisZSetCommands
All Known Subinterfaces:
RedisClusterConnection, RedisConnectionUtils.RedisConnectionProxy, StringRedisConnection
All Known Implementing Classes:
AbstractRedisConnection, DefaultStringRedisConnection, JedisClusterConnection, JedisConnection, LettuceClusterConnection, LettuceConnection

public interface RedisConnection extends RedisCommandsProvider, DefaultedRedisConnection, AutoCloseable
A connection to a Redis server. Acts as an common abstraction across various Redis client libraries (or drivers). Additionally performs exception translation between the underlying Redis client library and Spring DAO exceptions. The methods follow as much as possible the Redis names and conventions.

Redis connections, unlike perhaps their underlying native connection are not Thread-safe and should not be shared across multiple threads.

Author:
Costin Leau, Christoph Strobl, Mark Paluch, James Howe
  • Method Details

    • close

      void close() throws DataAccessException
      Closes (or quits) the connection.
      Specified by:
      close in interface AutoCloseable
      Throws:
      DataAccessException
    • isClosed

      boolean isClosed()
      Indicates whether the underlying connection is closed or not.
      Returns:
      true if the connection is closed, false otherwise.
    • getNativeConnection

      Object getNativeConnection()
      Returns the native connection (the underlying library/driver object).
      Returns:
      underlying, native object
    • isQueueing

      boolean isQueueing()
      Indicates whether the connection is in "queue"(or "MULTI") mode or not. When queueing, all commands are postponed until EXEC or DISCARD commands are issued. Since in queueing no results are returned, the connection will return NULL on all operations that interact with the data.
      Returns:
      true if the connection is in queue/MULTI mode, false otherwise
    • isPipelined

      boolean isPipelined()
      Indicates whether the connection is currently pipelined or not.
      Returns:
      true if the connection is pipelined, false otherwise
      See Also:
    • openPipeline

      void openPipeline()
      Activates the pipeline mode for this connection. When pipelined, all commands return null (the reply is read at the end through closePipeline(). Calling this method when the connection is already pipelined has no effect. Pipelining is used for issuing commands without requesting the response right away but rather at the end of the batch. While somewhat similar to MULTI, pipelining does not guarantee atomicity - it only tries to improve performance when issuing a lot of commands (such as in batching scenarios).

      Note:

      Consider doing some performance testing before using this feature since in many cases the performance benefits are minimal yet the impact on usage are not.
      See Also:
    • closePipeline

      List<Object> closePipeline() throws RedisPipelineException
      Executes the commands in the pipeline and returns their result. If the connection is not pipelined, an empty collection is returned.
      Returns:
      the result of the executed commands.
      Throws:
      RedisPipelineException - if the pipeline contains any incorrect/invalid statements
    • getSentinelConnection

      RedisSentinelConnection getSentinelConnection()
      Returns:
      Since:
      1.4