Home  >  Article  >  Database  >  How to set a password for redis in Windows

How to set a password for redis in Windows

王林
王林forward
2023-05-30 14:40:238478browse

There are two ways to set a password.

1. Set the password through the command line.

Run cmd to switch to the redis root directory, start the server first

>redis-server.exe

Open another cmd to switch to the redis root directory, start the client

>redis-cli.exe -h 127.0.0.1 -p 6379

The client uses config get requirepass command to view the password

>config get requirepass
1)"requirepass"
2)""    //默认空

The client uses the config set requirepass yourpassword command to set the password

>config set requirepass 123456
>OK

Once the password is set, the password must be verified first, otherwise all operations will be unavailable

>config get requirepass
(error)NOAUTH Authentication required

Use auth password to verify the password

>auth 123456
>OK
>config get requirepass
1)"requirepass"
2)"123456"

You can also log out and log in again

The password set on the command line will become invalid after the service is restarted, so this method is generally not used.

2. Set the password for the configuration file

Find the redis.windows.conf configuration file in the redis root directory, search for requirepass, find the comment password line, and add the password as follows:

# requirepass foobared
requirepass tenny     //注意,行前不能有空格

After restarting the service, after the client logs in again, it is found that the

>config get requirepass
1)"requirepass"
2)""

password is still empty?

Method after online query: Create a shortcut to redis-server.exe, right-click the shortcut properties, add redis.windows.conf after the target, here is the key, although you have modified the .conf file, but The exe does not use this conf, so we need to manually specify and the exe will run according to the modified conf, and it will be OK.

So, here I restart the redis service again (specify the configuration file)

>redis-server.exe redis.windows.conf

The client logs in again, OK.

>redis-cli.exe -h 127.0.0.1 -p 6379 -a 123456
>config get requirepass
1)"requirepass"
2)"123456"

Question: There are two configuration files redis.windows.conf and redis.windows-server.conf in the redis directory. I saw on the Internet that some people use the former and some use the latter. I don’t know which one should I use? Which one to use. After looking at the two files, there is no difference, so I personally use the former.

The above is the detailed content of How to set a password for redis in Windows. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete