Skip navigation links
Lettuce

Package io.lettuce.core.failover.health

Health check infrastructure for automatic failover in multi-database Redis connections.

See: Description

Package io.lettuce.core.failover.health Description

Health check infrastructure for automatic failover in multi-database Redis connections.

Health Check Strategies

This package provides a pluggable health check system for monitoring Redis database endpoints. Custom health check strategies can be implemented by extending HealthCheckStrategy.

Built-in Strategies

Example: Custom HTTP Health Check

 
 {
     @code
     public class HttpHealthCheckStrategy extends AbstractHealthCheckStrategy {

         private final String healthCheckUrl;

         public HttpHealthCheckStrategy(Config config, String healthCheckUrl) {
             super(config);
             this.healthCheckUrl = healthCheckUrl;
         }

         @Override
         public HealthStatus doHealthCheck(RedisURI endpoint) {
             try {
                 HttpURLConnection conn = (HttpURLConnection) new URL(healthCheckUrl).openConnection();
                 int code = conn.getResponseCode();
                 conn.disconnect();
                 return (code >= 200 && code < 300) ? HealthStatus.HEALTHY : HealthStatus.UNHEALTHY;
             } catch (Exception e) {
                 return HealthStatus.UNHEALTHY;
             }
         }
 
     }

     // Usage:
     HealthCheckStrategySupplier supplier = (uri, factory) -> new HttpHealthCheckStrategy(HealthCheckStrategy.Config.create(),
             "http://health-endpoint/check");
     DatabaseConfig config = DatabaseConfig.builder(redisURI).healthCheckStrategySupplier(supplier).build();
 }
 
Since:
7.4
Author:
Ali Takavci, Ivo Gaydazhiev
Skip navigation links
Lettuce

Copyright © 2026 lettuce.io. All rights reserved.