Redis saves data in memory, but it also writes data to the hard disk regularly.
Redis has two ways to save data:
Snapshot mode (Snapshot)
It supports two Snapshot mode:
Scheduled snapshot, which saves the data in the memory to the disk at a certain time.
Quantitative snapshot, that is, saving the data to disk after the data changes a certain number of times.
You can also combine these two methods, such as changing 1000 times and saving the data more than 60 seconds from the last save time.
Write mode (Append Only File)
In this mode, Redis will save all commands that modify data (such as Update, Set), etc. into an append-only file. ASAP file, when Redis restarts, it will re-execute the commands in this file.
Where is the data saved?
The data is saved in a data file. The specific file name depends on the Redis configuration file, that is, Redis.conf
config get dbfilename (return dump.rdb)
You can use config set dbfilename new (modify the file you want to save the data in)
How to export the data?
When Redis writes data, it first writes it to a temp file, and then renames the temp file to a predefined file, so even if Redis is running, you can directly copy this file with the cp command.
cp /usr/loca/redis/demo.rdb /home/greenerycn/db/demo.rdb
The above is the detailed content of Where is redis data stored?. For more information, please follow other related articles on the PHP Chinese website!