Package com.redis.vl.redis
Class RedisConnectionManager
java.lang.Object
com.redis.vl.redis.RedisConnectionManager
- All Implemented Interfaces:
Closeable,AutoCloseable
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 Summary
ConstructorsConstructorDescriptionCreate a new connection manager with the given configuration.RedisConnectionManager(SentinelConfig config) Create a new connection manager with Sentinel configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the connection manager and release resources<T> TExecute a command with the Redis client.voidexecuteVoid(Consumer<redis.clients.jedis.UnifiedJedis> command) Execute a command without a return value.static RedisConnectionManagerfrom(RedisConnectionConfig config) Create a connection manager from configuration.static RedisConnectionManagerCreate a connection manager from a URI.static RedisConnectionManagerCreate a connection manager from host and port.redis.clients.jedis.UnifiedJedisGet the underlying UnifiedJedis client.booleanCheck if the connection manager is connected.
-
Constructor Details
-
RedisConnectionManager
Create a new connection manager with the given configuration.- Parameters:
config- The Redis connection configuration
-
RedisConnectionManager
Create a new connection manager with Sentinel configuration.- Parameters:
config- The Sentinel connection configuration
-
-
Method Details
-
from
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
Create a connection manager from host and port.- Parameters:
host- The Redis hostport- The Redis port- Returns:
- A new RedisConnectionManager instance
-
from
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
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
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-