How Redis Persists Data ?

  • Home
  • How Redis Persists Data ?
admin April 1, 2024 0 Comments

How Redis Persists Data ?

Is Redis Data Persistence Useful in Practice?

Redis is an in-memory database. If the server shuts down, the data will be lost.
There are two ways to save Redis data to disk:

  • AOF (Append-Only File)
  • RDB (Redis Database)
AOF

Unlike a write-ahead log, the Redis AOF log writes after commands run. Redis runs commands to change the data in memory first. Then it writes the commands to the log file. AOF logs the commands instead of the data. This simpler design makes recovering data easier. Additionally, AOF records commands after they have executed in memory. So it does not block current write operations.

RDS

The limitation of AOF is that it saves commands instead of data. When we use the AOF log to recover data, the whole log must be scanned. When the log size is large, Redis takes longer to recover. So Redis offers another way to save data – RDB. RDB records snapshots of data at certain times. When the server needs recovery, the data snapshot can load directly into memory for fast recovery.

Step 1: The main thread forks the “bgsave” sub-process, which shares all the in-memory data. “bgsave” reads the data from the main thread and writes it to the RDB file.
Steps 2 and 3: If the main thread changes data, a copy is created.
Steps 4 and 5: The main thread then operates on the copy. Meanwhile, the “bgsave” sub-process continues writing data to the RDB file.

My Opinion

Recovery from disk takes too long. For most uses where Redis is used as a cache, using Redis replication and promoting the replica if the main Redis server fails catastrophically is better.

For any technical assistance or further inquiries, whether for business or personal use, we are here to help, Feel free to reach out to us at info@regitsfy.com

Leave Comment