redis连接Unable to connect to Redis

简介

今天本地springboot项目配置连接redis,一直报连接失败

Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
Caused by: io.lettuce.core.RedisCommandExecutionException: NOAUTH HELLO must be called with the client already authenticated, otherwise the HELLO AUTH <user> <pass> option can be used to authenticate the client and select the RESP protocol version at the same time

这样保持报错
下面来看如何解决的

解决方法

修改redis配置

1、设置可连接redis的网卡

指定了bind,则说明只允许来自指定网卡的Redis请求。如果没有指定或者指定为:0.0.0.0,就说明可以接受来自任意一个网卡的Redis请求。
查看网卡指令:ifconfig

bind 0.0.0.0

0.0.0.0代表所有服务器均可连接
在这里插入图片描述

2、设置保护模式为:yes

同样因为本机调试,避免掉误连的情况发上

protected-mode yes

在这里插入图片描述

3、设置连接密码

requirepass redis

在这里插入图片描述

4、重启redis

5、设置本地项目连接redis密码

在这里插入图片描述

6、重启项目

连接未报错,项目启动成功

总结:

出现连接错误的排查方向
1、redis服务配置的网卡限制:bind命令是否允许连接
2、redis的保护模式是否允许远程连接:protected-mode命令(yes为开启保护模式,不允许远程连接,no为关闭保护模式,允许远程连接)
3、是否设置redis连接密码及同项目配置密码是否一致,我此次连接失败的主要原因是配置文件的password: redis的配置中冒号后面少了空格,配置未能正确读取
错误配置:password:redis
正确配置:password: redis

"Unable to connect to Redis"错误通常表示无法连接Redis数据库。根据引用和引用中的错误信息,问题可能出在以下几个方面: 1. Redis服务器配置问题:可能是Redis服务器的网卡限制了连接,可以检查bind命令是否允许连接。此外,还要检查Redis的保护模式是否允许远程连接,可以通过protected-mode命令来查看和调整。 2. 密码配置问题:如果Redis服务器设置了密码,那么连接Redis时需要提供正确的密码。可以检查项目配置中的密码是否正确,并确保与Redis配置一致。 3. 其他网络或配置问题:还有其他可能导致连接失败的问题,例如网络故障、防火墙限制等。在排除了上述两个可能原因后,可以进一步检查网络连接是否正常,并确保没有其他配置问题。 总之,"Unable to connect to Redis"错误通常是由于Redis服务器配置、密码配置或其他网络或配置问题导致的。需要根据具体情况进行排查和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Unable to connect to Redis无法连接Redis](https://blog.csdn.net/rej177/article/details/129206289)[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_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [redis连接Unable to connect to Redis](https://blog.csdn.net/qq_42668072/article/details/130805592)[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_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值