Home > Database > Redis > body text

How to set a password for redis in Windows

王林
Release: 2023-05-30 14:40:23
forward
8464 people have browsed it

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
Copy after login

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

>redis-cli.exe -h 127.0.0.1 -p 6379
Copy after login

The client uses config get requirepass command to view the password

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

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

>config set requirepass 123456
>OK
Copy after login

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

>config get requirepass
(error)NOAUTH Authentication required
Copy after login

Use auth password to verify the password

>auth 123456
>OK
>config get requirepass
1)"requirepass"
2)"123456"
Copy after login

You can also log out and log in again

Copy after login

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     //注意,行前不能有空格
Copy after login

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

>config get requirepass
1)"requirepass"
2)""
Copy after login

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
Copy after login

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"
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!