From 2b67bbe07d2e8a7f15165e549fc7f439fe086a5f Mon Sep 17 00:00:00 2001 From: Huang Xiao Date: Fri, 28 Nov 2025 17:15:23 +0800 Subject: [PATCH] Set the version to 'unknown' when redis_version is missing See gh-48320 Signed-off-by: Huang Xiao --- .../boot/actuate/data/redis/RedisHealth.java | 2 +- .../redis/RedisHealthIndicatorTests.java | 13 +++++++++++++ .../RedisReactiveHealthIndicatorTests.java | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/data/redis/RedisHealth.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/data/redis/RedisHealth.java index 836d9d7b402..70efe2ce28c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/data/redis/RedisHealth.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/data/redis/RedisHealth.java @@ -34,7 +34,7 @@ final class RedisHealth { } static Builder up(Health.Builder builder, Properties info) { - builder.withDetail("version", info.getProperty("redis_version")); + builder.withDetail("version", info.getProperty("redis_version", "unknown")); return builder.up(); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java index b18dc8bb46b..0a778439579 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java @@ -62,6 +62,19 @@ class RedisHealthIndicatorTests { assertThat(health.getDetails()).containsEntry("version", "2.8.9"); } + @Test + void redisIsUpWithMissingVersion() { + Properties info = new Properties(); + RedisConnection redisConnection = mock(RedisConnection.class); + RedisServerCommands serverCommands = mock(RedisServerCommands.class); + given(redisConnection.serverCommands()).willReturn(serverCommands); + given(serverCommands.info()).willReturn(info); + RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection); + Health health = healthIndicator.health(); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails()).containsEntry("version", "unknown"); + } + @Test void redisIsDown() { RedisConnection redisConnection = mock(RedisConnection.class); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java index e9a1ed744e2..9e2247cc993 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java @@ -68,6 +68,23 @@ class RedisReactiveHealthIndicatorTests { then(redisConnection).should().closeLater(); } + @Test + void redisIsUpWithMissingVersion() { + Properties info = new Properties(); + ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class); + given(redisConnection.closeLater()).willReturn(Mono.empty()); + ReactiveServerCommands commands = mock(ReactiveServerCommands.class); + given(commands.info("server")).willReturn(Mono.just(info)); + RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands); + Mono health = healthIndicator.health(); + StepVerifier.create(health).consumeNextWith((h) -> { + assertThat(h.getStatus()).isEqualTo(Status.UP); + assertThat(h.getDetails()).containsOnlyKeys("version"); + assertThat(h.getDetails()).containsEntry("version", "unknown"); + }).expectComplete().verify(Duration.ofSeconds(30)); + then(redisConnection).should().closeLater(); + } + @Test void healthWhenClusterStateIsAbsentShouldBeUp() { ReactiveRedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory(null);