Linux下redis设置密码不生效的原因

前因:

我一直使用命令行的方式设置密码

127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass "123456"
OK

然后我就shutdown关闭redis
然后关闭服务器

127.0.0.1:6379> shutdown
not connected> 

开启服务器(一定要在根目录开启)

[root@VM-16-15-centos bin]# redis-server myredisconfig/redis.conf
12295:C 27 Oct 2021 10:16:42.271 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12295:C 27 Oct 2021 10:16:42.271 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12295, just started

后来发现根本没生效。

正文:然后使用了直接改conf配置文件的方法:

先进入你用来生效的配置文件:(我的文件名叫myredisconfig)

[root@VM-16-15-centos bin]# cd myredisconfig/
[root@VM-16-15-centos myredisconfig]# vi redis.conf

然后找到
然后下一步先去开启redis**(记住这里的参数一定要选你刚改的配置conf,不然就是redis默认的了)**

[root@VM-16-15-centos bin]# redis-server myredisconfig/redis.conf
12821:C 27 Oct 2021 10:20:27.013 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12821:C 27 Oct 2021 10:20:27.013 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12821, just started
12821:C 27 Oct 2021 10:20:27.013 # Configuration loaded


然后开启客户端验证:发现可以了

[root@VM-16-15-centos bin]# redis-cli -p 6379
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 

也可以在idea中用jedis验证一下试试:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45678130/article/details/120987691