1. Setting the password through the configuration file
Locate the following files in the Redis installation directory
Linux:/etc/redis.conf
Windows (my Windwos install-free version): E:\redis\redis-2.4.5-win32-win64\64bit
Found in the article
#requirepass foobared
Remove the comment before the line, and change the password to the desired password, save the file
Requirepass Myredis
2. Set a password by command
127.0. 0.1:6379[1set127.0. 0.1:6379[1get requirepass1"Requirepass "2"my_redis "
No need to restart Redis
Using the old password configured in the configuration file in the first step to sign in to Redis, you will find that the original password is not available and the operation is rejected
127.0. 0.1 6379 -127.0. 0.1:6379get requirepass (Error) ERR operation not permitted
Log in to Redis with the modified password to perform the appropriate action
127.0. 0.1 6379 -127.0. 0.1:6379get requirepass1"requirepass" 2"My_redis
Try to restart Redis, log in to Redis with the newly configured password, discover that the new password is invalid, and Redis re-uses the password in the configuration file
sudo service redis restartstopping redis-server: [OK]starting Redis-server: [OK]redis-cli-h127.0.0.1-P6379-a My_redisredis127.0.0.1:6379> ConfigGetRequirepass (Error) ERR operation not Permittedredis-cli-h127.0.0.1-P6379-a Myredisredis127.0.0.1:6379> ConfigGetRequirepass1)"Requirepass"2)"Myredis"
In addition to setting a password with the-a parameter at login, you can log in without specifying a password and authenticate before performing the operation.
Redis-cli-h127.0.0.1-P6379Redis127.0.0.1:6379> ConfigGetRequirepass (Error) ERR operation not Permittedredis127.0.0.1:6379>Auth Myredisokredis127.0.0.1:6379> ConfigGetRequirepass1)"Requirepass"2)"Myredis"
3.master configured the password, slave how to configure
If master is configured with a password, slave must also configure the appropriate password parameters otherwise it will not be able to replicate normally.
Locate the following line in the config file in slave, remove the comment, and change the password
#masterauth Mstpassword
Restart Redis
Linux
sudo service Redis restart# or sudo service redis stopsudo redis-server/etc/redis.conf
Windows (before starting the service, loading the profile later)
Redis-server.exe redis.conf
redis-Setting a password