How does Redis interact with disk memory when saving data?
sobes.tech AI
Answer from AI
Redis is an in-memory database that stores data in RAM for high-speed access. However, Redis uses two main mechanisms for data persistence to disk:
-
RDB (Redis Database Backup) — periodically creates snapshots of the entire database and writes them to a disk file. This occurs on a schedule or when certain conditions are met (e.g., number of changes).
-
AOF (Append Only File) — logs all write operations performed by Redis. Each write command is appended to a file, allowing the database state to be restored by replaying all operations.
When Redis starts, it loads data from the RDB file or AOF to restore the state. During operation, data is kept in memory, and snapshots or operation logs are written to disk.
Thus, Redis balances speed (RAM) and data durability (disk storage).