Class RedisConnectionManager

java.lang.Object
com.redis.vl.redis.RedisConnectionManager
All Implemented Interfaces:
Closeable, AutoCloseable

public class RedisConnectionManager extends Object implements Closeable
Manages Redis connections using the modern Jedis 7.2+ API.

This class uses RedisClient for standalone connections and RedisSentinelClient for Sentinel-managed high availability deployments.

  • Constructor Details

    • RedisConnectionManager

      public RedisConnectionManager(RedisConnectionConfig config)
      Create a new connection manager with the given configuration.
      Parameters:
      config - The Redis connection configuration
    • RedisConnectionManager

      public RedisConnectionManager(SentinelConfig config)
      Create a new connection manager with Sentinel configuration.
      Parameters:
      config - The Sentinel connection configuration
  • Method Details

    • from

      public static RedisConnectionManager from(String uri)
      Create a connection manager from a URI.

      Supports both standard Redis URLs and Sentinel URLs:

      • redis://[username:password@]host:port[/database] - Standard Redis connection
      • redis+sentinel://[username:password@]host1:port1,host2:port2/service_name[/database] - Sentinel connection
      Parameters:
      uri - The Redis connection URI
      Returns:
      A new RedisConnectionManager instance
    • from

      public static RedisConnectionManager from(String host, int port)
      Create a connection manager from host and port.
      Parameters:
      host - The Redis host
      port - The Redis port
      Returns:
      A new RedisConnectionManager instance
    • from

      public static RedisConnectionManager from(RedisConnectionConfig config)
      Create a connection manager from configuration.
      Parameters:
      config - The Redis connection configuration
      Returns:
      A new RedisConnectionManager instance
    • isConnected

      public boolean isConnected()
      Check if the connection manager is connected.
      Returns:
      True if client is available, false otherwise
    • getClient

      public redis.clients.jedis.UnifiedJedis getClient()
      Get the underlying UnifiedJedis client.

      Since RedisClient extends UnifiedJedis, this provides full access to all Redis operations.

      Returns:
      The UnifiedJedis client
      Throws:
      IllegalStateException - if the connection manager is not connected
    • execute

      public <T> T execute(Function<redis.clients.jedis.UnifiedJedis,T> command)
      Execute a command with the Redis client.
      Type Parameters:
      T - The return type of the command
      Parameters:
      command - The function to execute with the UnifiedJedis client
      Returns:
      The result of the command execution
    • executeVoid

      public void executeVoid(Consumer<redis.clients.jedis.UnifiedJedis> command)
      Execute a command without a return value.
      Parameters:
      command - The consumer to execute with the UnifiedJedis client
    • close

      public void close()
      Close the connection manager and release resources
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable