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 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
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/835a43e4da.html
