Redis设置密码(2种常见方式)

Redis设置密码方法一

通过配置文件Redis设置密码,首先打开配置文件:

在Linux系统中,配置文件通常位于/etc/redis/redis.conf,而在Windows系统中,则位于Redis的安装目录下。

在配置文件中找到并取消注释(去掉行首的#符号)以下行:

  1. # The requirepass is not compatable with aclfile option and the ACL LOAD
  2. # command, these will cause requirepass to be ignored.
  3. #
  4. # requirepass foobared

设置成:

  1. requirepass your_password

your_password替换为你想要设置的密码。

保存并关闭配置文件,重启Redis服务,使配置生效,这种方式是永久生效。

 

Redis设置密码方法二

通过命令设置密码,临时生效,重启服务器后密码失效。

通过Redis客户端连接到Redis服务器时,需要提供密码来进行身份验证,在命令行中,你可以使用以下命令连接到Redis服务器并进行身份验证:

  1. redis-cli -h your_host -p your_port -a your_password

your_host替换为Redis服务器的主机名或IP地址,your_port替换为Redis服务器的端口号,your_password替换为设置的密码。

评论交流
    说说你的看法
欢迎您,新朋友,感谢参与互动!