Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте AOF Persistence | Advanced Features and Security
Introduction to Redis
course content

Зміст курсу

Introduction to Redis

Introduction to Redis

1. Redis Fundamentals
2. The Essential Redis Commands
3. Data Types in Redis
4. Advanced Features and Security
5. Caching with Redis and Spring Boot

book
AOF Persistence

The illustration shows how Redis operates using AOF. A client command is first executed in memory for fast data access, and then the command is written to a file on disk to ensure reliable data recovery in case of a failure.

How AOF Works

When AOF mode is enabled, every write command sent to the server is saved to a file. Upon restarting Redis, the commands from the AOF file are read and used to restore the dataset.

Over time, this file can grow significantly in size as it contains the entire history of key changes. To address this, Redis periodically rewrites the file, removing unnecessary commands and retaining only the current state of each key. For instance, if we use a key named total and modify its value multiple times, the original AOF file might look like this:

After rewriting, Redis will keep only the latest value for the key:

When Redis appends a new command to the AOF file, the operating system initially saves it in a buffer before writing it to disk at specific intervals. If a power outage occurs, data still in the buffer may be lost. To minimize this risk, Redis flushes the buffer every second by default. You can configure it to write data to the disk immediately after each command, but this significantly slows down operations.

How to Enable AOF

To enable AOF, update the redis.conf file with the following settings:

When configuring AOF in Redis, you can choose how frequently data is synchronized to the disk. This affects both system performance and reliability:

  • appendfsync alwayssync after every operation (slower but most reliable);
  • appendfsync everysecsync once per second (optimal balance of performance and durability);
  • appendfsync nodata remains in memory until flushed by the system (fast but risky).

Difference Between AOF and RDB

Configuring Combined Persistence

You can enable both RDB and AOF simultaneously to combine their strengths. This approach provides a reliable backup (RDB) while minimizing data loss (AOF).

Summary

Persistence in Redis strikes a balance between performance and data reliability, allowing you to choose the approach that best suits your needs. If your priority is high performance, RDB is the ideal choice. On the other hand, if minimizing data loss is essential, AOF is more suitable. For those requiring maximum reliability, using both methods together provides the best results.

1. Which Redis persistence method minimizes data loss?

2. When should you use both RDB and AOF persistence in Redis?

Which Redis persistence method minimizes data loss?

Which Redis persistence method minimizes data loss?

Виберіть правильну відповідь

When should you use both `RDB` and `AOF` persistence in Redis?

When should you use both RDB and AOF persistence in Redis?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 6
We're sorry to hear that something went wrong. What happened?
some-alt