How to set password for redis in Windows

There are two ways to set a password, the first one can be used

1. Set the password on 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 and start the client

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

The client uses the config get requirepass command to view the password

>config get requirepass
1)"requirepass"
2)"" //default empty

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 are unavailable

>config get requirepass
(error)NOAUTH Authentication required

Verify password using auth password

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

You can also log out and log in again

redis-cli.exe -h 127.0.0.1 -p 6379 -a 123456

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

2. Configuration file setting password 

no use for this

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 //Note, there can be no spaces before the line

After restarting the service, the client logs in again and finds that

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

Password is still empty?

The method after online query: Create a shortcut to redis-server.exe, right-click the shortcut property, and add redis.windows.conf after the target. Here is the key. Although you have modified the .conf file, the exe does not use this conf , so we need to manually specify the exe to 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"

Guess you like

Origin blog.csdn.net/m1195900241/article/details/132205728