我试图在我的项目中使用 spring-data-redis 。当我在 yaml 文件中配置 redis 节点时,如下所示:
spring:
redis:
cluster:
max-redirects: 2
nodes: host1:6379,host1:6380,host1:6381
然后,spring-data-redis在内部创建集群的JedisConnectionFactory。但是如果我尝试通过以下方式配置:
spring:
redis:
cluster:
max-redirects: 2
nodes:
- host1:6379
- host1:6380
- host1:6381
然后,我必须在我的应用程序中为集群创建 JedisConnectionFactory 的 bean。
我猜当前版本的 spring-data-redis 不支持在 yaml 中以数组方式表示节点数量来创建集群。
我的建议是spring-boot/spring-data-redis开发者可以支持上述格式的yaml来内部创建redis集群吗?
最佳答案
如果您检查here ,可以像这样将 hostAndPort 作为一个丑陋的数组提供,与 spring.redis
属性组分开;
clusterHostAndPorts:
- host1:6379
- host1:6380
- host1:6381
在我本地测试过,确实有效,不支持你问的方式,可以看看here ,然后 here ,最后 here .
HostAndPort need to be seperated by ':'.
Host and Port String needs to specified as host:port
关于spring-boot - 在 spring-data-redis 中定义集群节点属性的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42967518/