如何排除弹簧执行器健康状况中的redis检查

hua*_*dyn 11 spring redis spring-boot spring-boot-actuator health-check

当 redis 关闭时,服务运行状况检查 api 响应 503。

{
    "status": "DOWN",
    "details": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 250790436864,
                "free": 95412813824,
                "threshold": 10485760
            }
        },
        "db": {
            "status": "UP",
            "details": {
                "database": "PostgreSQL",
                "hello": 1
            }
        },
        "refreshScope": {
            "status": "UP"
        },
        "redis": {
            "status": "DOWN",
            "details": {
                "error": "org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但实际上当redis宕机时服务是可用的。

服务状态可以不受redis状态影响吗?我还需要在健康检查 api 中查看 redis 详细信息。

Luc*_*újo 16

management.health.redis.enabled=false

添加此代码以在 application.yaml/properties 中禁用 Redis 运行状况检查


小智 4

我通常检查https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html这来找到类似你正在做的事情

在那里我发现了 management.health.redis.enabled (默认为 true),所以我的猜测是,如果你明确地将其设置为 false,它就会从你的健康检查中消失