There are two ways to set the redis password, one requires restarting the redis service, and the other does not require restarting the redis service. The following article will introduce these two methods to you, I hope it will be helpful to you.
Method 1: Set through the configuration file (/etc/redis.conf)
In this method, after setting the password You need to restart redis to take effect. First find the redis configuration file—redis.conf file, and then modify the requirepass inside (requirepass is the parameter for configuring the redis access password). This is originally commented out. Remove the comment and set the corresponding fields to what you want. Password required, save and exit. Just restart the redis service. (Recommended learning: Redis video tutorial)
I set the password here to 123
Method 2: Pass Command to set password
This method is relatively simple and does not require restarting the redis service. After connecting to redis, set it through the command, as follows:
config set requirepass 123456
In this way, the password is set to 123456
After setting, you can check the password through the following command
config get requirepass
After setting the password, when you exit and connect to redis again, you need to enter the password, otherwise it will not work. There are two ways to enter the password. One is to enter the password directly when connecting, but to enter the password after connecting, as follows:
Note: Through the command After you change the password, the password behind the requirepass field in the configuration file (/etc/redis.conf) will not be changed accordingly.
For more redis related technical knowledge, please visit the Redis usage tutorial column to learn!
The above is the detailed content of How to set a password for Redis. For more information, please follow other related articles on the PHP Chinese website!