Get the App
SLTechnology News&Howtos  ›  Database  › 

How does redis store data

Shulou Source: shulou.com Published: 2022-06-01 19:30:10 10月15日 Update

Today, the editor shares with you a detailed introduction of how redis stores data. I believe most people don't know much about it. In order to make you understand better, the editor summed up the following content for you. Without saying much, let's move on.

Redis saves data to memory, but it also writes data to the hard disk on a regular basis.

There are two ways for Redis to save data:

Snapshot mode (Snapshot)

It supports two snapshot modes:

Timed snapshot, that is, the data in memory is saved to disk at a certain time.

Quantitative snapshot, that is, the data is saved to disk after a certain number of changes.

You can also combine these two methods, such as changing 1000 times and saving data more than 60 seconds from the last save time.

Write mode (Append Only File)

In this mode, Redis saves all commands that modify the data (such as Update,Set) into an ASAP file that can only be appended, and when Redis restarts, it reexecutes the commands in this file.

Where is the data saved?

The data is saved to a data file. The specific file name depends on the configuration file of Redis, namely Redis.conf.

Config get dbfilename (returns dump.rdb)

You can use config set dbfilename new (modify the file where you want to save the data)

How does the data get to export?

When Redis writes data, it first writes to a temp file, and then renames the temp file to a predefined file, so even if Redis is running, you can copy the file directly with the cp command.

Cp / usr/loca/redis/demo.rdb / home/greenerycn/db/demo.rdb

The above is the knowledge summary of redis storage data, the content is more comprehensive, the editor believes that there may be some knowledge points that we may see or use in our daily work. I hope you can learn more from this article.

Tags: Data files snapshots patterns commands knowledge storage memory content methods time disks changes most that is copies file names daily work more times Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Huawei Redmi NVidia