#How to set a password for redis?
Password setting
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.
First of all, let’s introduce the setting method that needs to restart the redis service
That is, find the redis configuration file—redis.conf file, and then modify the requirepass inside. This was originally commented out. Remove the comments, set the corresponding fields behind to the password you want, save and exit. Just restart the redis service.
I set the password here to 123
Then there is a password setting method that does not require restarting the redis service
This is relatively simple , 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 the password is set, when you log out 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:
In fact, there is another A small problem is that after changing the password through the command line, the password behind the requirepass field in the configuration file will not be changed accordingly.
For more Redis related knowledge, please visit the Redis usage tutorial column!
The above is the detailed content of How to set password for redis. For more information, please follow other related articles on the PHP Chinese website!