Skip to content

Commit fe51e03

Browse files
committed
Support IPv6 addresses in spring.redis.sentinel.nodes
Fixes gh-32762
1 parent 1a14f39 commit fe51e03

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
2828
import org.springframework.data.redis.connection.RedisPassword;
2929
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
3030
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
31-
import org.springframework.util.Assert;
3231
import org.springframework.util.ClassUtils;
3332
import org.springframework.util.StringUtils;
3433

@@ -144,9 +143,7 @@ private List<RedisNode> createSentinels(RedisProperties.Sentinel sentinel) {
144143
List<RedisNode> nodes = new ArrayList<>();
145144
for (String node : sentinel.getNodes()) {
146145
try {
147-
String[] parts = StringUtils.split(node, ":");
148-
Assert.state(parts.length == 2, "Must be defined as 'host:port'");
149-
nodes.add(new RedisNode(parts[0], Integer.parseInt(parts[1])));
146+
nodes.add(RedisNode.fromString(node));
150147
}
151148
catch (RuntimeException ex) {
152149
throw new IllegalStateException("Invalid redis sentinel property '" + node + "'", ex);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -280,6 +280,16 @@ void testRedisConfigurationWithSentinel() {
280280
.isTrue());
281281
}
282282

283+
@Test
284+
void testRedisConfigurationWithIpv6Sentinel() {
285+
List<String> sentinels = Arrays.asList("[0:0:0:0:0:0:0:1]:26379", "[0:0:0:0:0:0:0:1]:26380");
286+
this.contextRunner
287+
.withPropertyValues("spring.redis.sentinel.master:mymaster",
288+
"spring.redis.sentinel.nodes:" + StringUtils.collectionToCommaDelimitedString(sentinels))
289+
.run((context) -> assertThat(context.getBean(LettuceConnectionFactory.class).isRedisSentinelAware())
290+
.isTrue());
291+
}
292+
283293
@Test
284294
void testRedisConfigurationWithSentinelAndDatabase() {
285295
this.contextRunner.withPropertyValues("spring.redis.database:1", "spring.redis.sentinel.master:mymaster",

0 commit comments

Comments
 (0)