高效解决 springBoot 集成 Redis 出现的: Unable to connect to Redis 问题

报错如下:

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)
	

解决办法:

  1. 查看有没有启动Redis服务器。

  2. redis的配置application.yml(或application.properties)中
    spring.redis.timeout连接超时时间(毫秒)中设置不能为0,
    一般修改如下:spring.redis.timeout=5000。

  3. 找到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 地址的请求,注释掉后,则表示将处理所有请求)。

  4. 如果在Redis中没有配置requirepass ,那么在application.properties(或application.yaml)中就不要写spring.redis.password。

  • 70
    点赞
  • 89
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis 是一个Spring Data Redis库中的异常,表示无法连接到Redis数据库。 通常情况下,这个异常的原因可以归结为以下几个方面: 1. Redis服务器未启动或未正确配置。你可以检查Redis服务器的状态以及配置文件中的主机和端口信息是否正确。确保Redis服务器正在运行,并且你的应用程序可以访问到它。 2. 网络连接问题。可能是由于网络连接中断、防火墙配置或者Redis服务器配置中的限制导致的。你可以检查网络连接是否正常,并确保防火墙允许你的应用程序与Redis服务器进行通信。 3. 密码错误。如果Redis服务器设置了密码,你需要在应用程序中正确地配置密码。检查你的应用程序配置文件中的密码是否正确。 综上所述,如果你遇到了org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis异常,请检查Redis服务器的状态和配置、网络连接以及密码是否正确配置。如果问题仍然存在,你可以尝试重启Redis服务器或联系Redis技术支持寻求帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [springboot连接redis出现org.springframework.data.redisRedisConnectionFailureException异常](https://blog.csdn.net/m0_67393828/article/details/123684060)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [org.springframework.data.redis.RedisConnectionFailureException异常解决](https://blog.csdn.net/Sexycool/article/details/122352805)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值