【redis】如何给redis设置密码

【进入redis目录】

cd /home/hy/redis-6.2.6

这个目录是我解压的目录,大家遵照自己的目录来就行。

【编辑redis.conf】

vi redis.conf

将#requirepass foorbared一行打开,将foorbared改成你期望的密码,最终是 requirepass 123456

然后保存退出。

【启动redis】

[hy@localhost redis-6.2.6]$ cd src
[hy@localhost src]$ ./redis-server ../redis.conf

【测试】

[hy@localhost src]$ ./redis-cli
127.0.0.1:6379> get ufo
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> get ufo
"www.ufo.com"
127.0.0.1:6379> exit
[hy@localhost src]$

可以看到,首次取ufo的值时,redis不让,在输入auth 123456后,值就出来了。

【参考资料】

https://blog.csdn.net/weixin_35696075/article/details/116811046

END

 

posted @ 2022-03-04 10:58  逆火狂飙  阅读(587)  评论(0)    收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东