Redis 简明教程

Redis - Security

可以保护 Redis 数据库,以便任何连接客户端在执行命令之前需要进行身份验证。要保护 Redis,需要在配置文件中设置密码。

Redis database can be secured, such that any client making a connection needs to authenticate before executing a command. To secure Redis, you need to set the password in the config file.

Example

以下示例演示了保护 Redis 实例的步骤。

Following example shows the steps to secure your Redis instance.

127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) ""

默认情况下,此属性为空,这意味着为此实例未设置密码。可以通过执行以下命令来更改此属性。

By default, this property is blank, which means no password is set for this instance. You can change this property by executing the following command.

127.0.0.1:6379> CONFIG set requirepass "tutorialspoint"
OK
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) "tutorialspoint"

设置密码后,如果任何客户端在未经过身份验证的情况下运行命令,则 (error) NOAUTH Authentication required . error 将返回。因此,客户端需要使用 AUTH 命令来验证自身。

After setting the password, if any client runs the command without authentication, then (error) NOAUTH Authentication required. error will return. Hence, the client needs to use AUTH command to authenticate himself.

Syntax

以下是 AUTH 命令的基本语法。

Following is the basic syntax of AUTH command.

127.0.0.1:6379> AUTH password

Example

127.0.0.1:6379> AUTH "tutorialspoint"
OK
127.0.0.1:6379> SET mykey "Test value"
OK
127.0.0.1:6379> GET mykey
"Test value"