"Go" Redis Configuration authentication Password

Source: Internet
Author: User

Original link http://blog.csdn.net/zyz511919766/article/details/42268219

Redis Configuration Password

1. Configuring with configuration Files
The Yum-style installation of Redis profiles is typically in/etc/redis.conf, which opens the configuration file to find

[Plain]View Plaincopy
    1. #requirepass foobared

Remove the comment before the line, and change the password to the desired password, save the file

[Plain]View Plaincopy
    1. Requirepass Myredis

Restart Redis

[Plain]View Plaincopy
    1. sudo service Redis restart
    2. #或者
    3. sudo service Redis stop
    4. sudo redis-server/etc/redis.conf

This is the time to try to log in to Redis and find that it is possible to mount, but the specific command is prompt operation is not allowed

[Plain]View Plaincopy
    1. Redis-cli-h 127.0.0.1-p 6379
    2. Redis 127.0.0.1:6379>
    3. Redis 127.0.0.1:6379> Keys *
    4. (Error) ERR Operation not permitted
    5. Redis 127.0.0.1:6379> Select 1
    6. (Error) ERR Operation not permitted
    7. Redis 127.0.0.1:6379[1]>

Try to log in with a password and execute a specific command to see that it can be executed successfully

[Plain]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
    1. Redis-cli-h 127.0.0.1-p 6379-a Myredis
    2. Redis 127.0.0.1:6379> Keys *
    3. 1) "MySet"
    4. 2) "Mysortset"
    5. Redis 127.0.0.1:6379> Select 1
    6. Ok
    7. Redis 127.0.0.1:6379[1]> config Get requirepass
    8. 1) "Requirepass"
    9. 2) "Myredis"


2. Configure through the command line

[Plain]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
    1. Redis 127.0.0.1:6379[1]> Config set requirepass My_redis
    2. Ok
    3. Redis 127.0.0.1:6379[1]> config Get requirepass
    4. 1) "Requirepass"
    5. 2) "My_redis"

Password invalidation without restarting Redis,redis reboot
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

[Plain]View Plaincopy
    1. Redis-cli-h 127.0.0.1-p 6379-a Myredis
    2. Redis 127.0.0.1:6379> config Get requirepass
    3. (Error) ERR Operation not permitted

Log in to Redis with the modified password to perform the appropriate action

[Plain]View Plaincopy
    1. Redis-cli-h 127.0.0.1-p 6379-a My_redis
    2. Redis 127.0.0.1:6379> config Get requirepass
    3. 1) "Requirepass"
    4. 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

[Plain]View Plaincopy
  1. sudo service Redis restart
  2. stopping redis-server: [OK]
  3. Starting redis-server: [OK]
  4. Redis-cli-h 127.0.0.1-p 6379-a My_redis
  5. Redis 127.0.0.1:6379> config Get requirepass
  6. (Error) ERR Operation not permitted
  7. Redis-cli-h 127.0.0.1-p 6379-a Myredis
  8. Redis 127.0.0.1:6379> config Get requirepass
  9. 1) "Requirepass"
  10. 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.

[Plain]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
    1. Redis-cli-h 127.0.0.1-p 6379
    2. Redis 127.0.0.1:6379> config Get requirepass
    3. (Error) ERR Operation not permitted
    4. Redis 127.0.0.1:6379> Auth Myredis
    5. Ok
    6. Redis 127.0.0.1:6379> config Get requirepass
    7. 1) "Requirepass"
    8. 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

[Plain]View Plaincopy
      1. #masterauth Mstpassword

"Go" Redis Configuration authentication 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.