报错如下:
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.136.222:6379
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1189)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1168)
解决办法:
-
查看有没有启动Redis服务器。
-
redis的配置application.yml(或application.properties)中
spring.redis.timeout连接超时时间(毫秒)中设置不能为0,
一般修改如下:spring.redis.timeout=5000。 -
找到redis的配置文件 redis.conf : 执行 vim redis.conf
3.1 protected-mode yes 改为 protected-mode no (即该配置项表示是否开启保护模式,默认是开启,开启后Redis只会本地进行访问,拒绝外部访问)。
3.2 注释掉 bin127.0.0.1 即 #bin 127.0.0.1 (ps: 不注释掉,表示指定 redis 只接收来自于该 IP 地址的请求,注释掉后,则表示将处理所有请求)。 -
如果在Redis中没有配置requirepass ,那么在application.properties(或application.yaml)中就不要写spring.redis.password。
————————————————
版权声明:本文为优快云博主「中土月鱼」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/wandongshengno_1/article/details/102749689

本文介绍了Spring Boot应用在尝试连接Redis时遇到的`RedisConnectionFailureException`错误,以及如何解决。首先,检查Redis服务器是否已启动;其次,确保`spring.redis.timeout`配置非0,如设置为5000ms;接着,修改Redis配置文件`redis.conf`,关闭保护模式(`protected-mode no`)并取消127.0.0.1的限制。若未配置`requirepass`,则不要在应用配置中设置`spring.redis.password`。
416

被折叠的 条评论
为什么被折叠?



