This article mainly introduces the installation and use of Redis, and analyzes the download, installation, startup, settings and related operating instructions of the Redis database in the form of examples. Friends in need can refer to it
The examples in this article summarize the installation and use of Redis. Share it with everyone for your reference, the details are as follows:
1. Download:
Project address: https://github.com/MSOpenTech /redis
Download address: https://github.com/MSOpenTech/redis/releases
Note, download the zip version, not the msi version.
2. Installation:
Unzip, copy to the root directory of the e drive, and rename the folder to redis (remove the version number and the like) ), the installation is completed.
3. Start:
Open cmd, enter redis, enter the command redis-server.exe redis.windows.conf
, press Enter, the startup is completed.
A square box pattern appears even if the startup is successful.
Otherwise the startup fails.
In the development environment, cmd must be opened as an administrator to start successfully. If it is a server environment and you are the administrator, you do not need to do this in particular.
4. Test:
Open another cmd, enter redis, enter the command redis-cli.exe, and press Enter to enter redis operating status.
Enter set age 21
, and OK will be returned, indicating that the writing is successful.
Enter get age
, and 21 will be returned, indicating that the value is successfully obtained.
Finished test.
If the connection you want to connect is not local, or the port has been changed, and you find that you cannot connect, you should do this:
redis-cli.exe -h host IP -p new port number
For example, assuming the port has been changed to 666, then it should be written like this:
redis-cli.exe -p 666
This way you can connect
5. Persistence:
① AOF:
Modify in redis.windows.conf:
appendonly yes
That’s it. An appendonly.aof file will be generated in the program folder, which is a log file, and the data will be stored in this file.
② RDB:
By default, a data snapshot named dump.rdb will be created in the program folder. The logic of the snapshot is as follows:
#900秒后且至少1个key发生变化时创建快照 save 900 1 #300秒后且至少10个key发生变化时创建快照 save 300 10 #60秒后且至少10000个key发生变化时创建快照 save 60 10000
You can disable the creation of snapshots by commenting out save.
③ What is RedisQFork.dat:
This is the memory mapping of redis. When redis starts, such a file will be created. When redis is closed, this file will be created. And it disappeared. This file is to write the memory data into it and make a mapping.
The more data there is, the larger the bat will be, which will occupy the space of the c drive. The solution is to change the path to another drive.
Note: The 3.2 version I downloaded did not find the heapdir, and I set it myself heapdir e:\redis\ Then an error will be reported when starting, the unknown parameter heapdir, and the entire The computer cannot find the RedisQFork file. I suspect that the new version of redis has abandoned this mapping.
For testing, I downloaded version 2.8, which does have the heapdir option.
6. Start up:
Configure redis as a service:
Open cmd as administrator and enter e disk, enter:
Copy code The code is as follows:
E:\redis\redis-server.exe --service-install E:\redis\ redis.windows.conf --loglevel verbose
Press Enter and the service is created.
You can open and run -services.msc
-you can see the Redis service.
Restart the computer and Redis has been started. You can open redis-cli testing.
Delete service:
E:\redis\redis-server --service-uninstall
##7. Security
Modify inredis.windows.conf:
① Binding ip
can be local or External network, this is generally bound by default (redis3.2)bind 127.0.0.1
② Modify the default port
Default Change 6379 to other ports③ Disable dangerous commands
Set it to "" to disable the following commands:rename-command FLUSHALL "" rename-command CONFIG "" rename-command EVAL ""
8. Fuzzy query through command line
If we determine a key, the query will be like this:get xxx
keys test*
9. Expiration time
#When using redis to write the expiration time in php, it must be forced to be of type (int), whether it is string or double. No, only int can. related suggestion:Partial summary of Redis commands in PHP
The above is the detailed content of Summary of Redis installation and usage methods. For more information, please follow other related articles on the PHP Chinese website!