DKW*_*Woo 2 spring redis lettuce docker spring-boot
我正在使用 Spring boot 2.2.5 和 Spring data redis 和 bitnami/redis-sentinel Sentinel docker 镜像。
bitnami/redis-sentinel docker 镜像与 docker compose 配合得很好。
我可以使用 redis-cli 连接到 redis。(cli 显示 127.0.0.1:6379 已连接)
但在我本地的 Spring boot 应用程序中,它不起作用。错误跟踪如下:
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 172.28.0.2:6379
at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:109) ~[spring-data-redis-2.2.5.RELEASE.jar:2.2.5.RELEASE]
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 172.28.0.2:6379
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) ~[lettuce-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /172.28.0.2:6379
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261) ~[netty-transport-4.1.45.Final.jar:4.1.45.Final]
Run Code Online (Sandbox Code Playgroud)
IP地址172.28.0.2是docker镜像中的redis master ip。
我的哨兵主机配置如下,127.0.0.1:26379,127.0.0.1:26379,127.0.0.1:26379
我想我的应用程序通过本地主机哨兵配置很好地获取了主信息。
那么为什么我的应用程序为 master 找到 172.28.0.2:6379 而不是 127.0.0.1:6379 ?
我是否需要更改该 docker 映像中的地址,或者我是否也应该在 docker 上运行我的应用程序?
任何帮助,将不胜感激!
我刚刚通过在 docker-compose 的环境中添加 REDIS_MASTER_HOST=127.0.0.1 (最初是“redis”)解决了我的问题。我发现在运行容器的 redis-sentinel.conf 中为监视器 reids master 设置了 172.28.0.2 6379,并且它没有随容器名称“redis”而改变。
之后,我的带有 Lettuce 客户端的 springb boot 应用程序可以在本地计算机上毫无问题地连接到 redis。
| 归档时间: |
|
| 查看次数: |
6909 次 |
| 最近记录: |