redis-Setting a password

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.