给 Redis 设置密码
Redis 设置密码需要在 Redis 配置文件中进行,具体如下:
打开 redis.conf 文件。若Redis是通过源码安装的,则该文件默认位于 /usr/local/redis/redis.conf。
使用文本编辑器(如vim)打开 redis.conf 文件,找到设置密码的相关配置项:
# requirepass foobared
在该行代码前添加#,表示注释,然后在下一行添加如下代码:
# 设置密码为 yourpassword
requirepass yourpassword
修改代码中的 yourpassword 为你期望设置的密码。
保存并关闭redis.conf文件。
在命令行中使用如下命令连接Redis服务器:redis-cli -h host -p port -a password
# 带密码访问 -a password
redis-cli -h 192.168.25.201 -p 6379 -a 123456