使用常规配置以及咨询豆包生成ipv6集群配置,发现最终还是报错

豆包

image.png
记录一下最终解决方案吧,需要手动解析ipv6 cluster地址,手动注入集群配置,因为spring-boot-starter-data-redis不知道ipv6 cluster,它本身支持cluster配置,但是不支持ipv6的cluster。
- spring配置
spring:
redis:
clusterFlag: true
password: xxxxx
nodes: "[fd20:d1a9:3c86:8111:12:0:1:xx]:6379,[fd20:d1a9:3c86:8111:12:0:1:xx]:6379,[fd20:d1a9:3c86:8111:12:0:1:xx]:6379"
- 注入配置
@Configuration
@ConditionalOnProperty(prefix = "spring.redis", name = "clusterFlag", havingValue = "true")
public class RedisClusterConfig {
@Value("${spring.redis.nodes}")
private String clusterNodes;
@Value("${spring.redis.password}")
private String password;
@Bean
public RedisClusterConfiguration redisClusterConfiguration() {
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration();
String[] serverArray = clusterNodes.split(",");
Set<RedisNode> nodes = new HashSet<>();
for (String ipPort : serverArray) {
//String[] ipAndPort = ipPort.split(":");
String ip = ipPort.substring(0, ipPort.lastIndexOf(":"));
String port = ipPort.substring(ipPort.lastIndexOf(":") + 1);
nodes.add(new RedisNode(ip, Integer.parseInt(port)));
}
redisClusterConfiguration.setClusterNodes(nodes);
redisClusterConfiguration.setPassword(RedisPassword.of(password));
return redisClusterConfiguration;
}
}