Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to

无法连接docker部署的redis

出现原因:

1、spring.redis.host

2、连接时间spring.redis.timeout

3、redis 没有设置密码 spring.redis.password=

解决方法:

1、如果web服务器的镜像和redis镜像在一个宿主机上,spring.redis.host 不能使用宿主机的IP地址,解决方法如下

Docker有4种网络模式,bridge是默认的网络模式。

①、查看redis容器对应的容器ID是多少

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

3961da6114c4 d3e35 “docker-entrypoint…” 4 days ago Up 4 days 0.0.0.0:6379->6379/tcp ecstatic_turing2

②、查看容器配置信息

# docker network inspect bridge

可以在Containers 信息中找到 ecstatic_turing的配置信息,如下

"3961da6114c4ee600438ec598703ec7312c6ecfde1b6055def0f910e0bc92632": 
			{
                "Name": "ecstatic_turing",
                "EndpointID": "4050d4e7d6c19c28258cc6a34bf0e589d22134c5eb02fea7f813606ee065c8b2",
                "MacAddress": "02:42:ac:11:00:04",
                "IPv4Address": "172.17.0.4/16",
                "IPv6Address": ""
            }

③、此时可以知道,配置spring.redis.host=172.17.0.4

2、将spring.redis.timeout=5000

3、如果redis没有设置密码,那就不写spring.redis.password= 或者只写 spring.redis.password=

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值