> For the complete documentation index, see [llms.txt](https://gchandra.gitbook.io/big-data-and-tools-with-nosql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gchandra.gitbook.io/big-data-and-tools-with-nosql/nosql/redis/persistence.md).

# Persistence

1. **RDB (Redis Database)**: This method takes snapshots of your database at specified intervals. It's efficient for saving a compact, point-in-time snapshot of your dataset. The RDB file is a binary file that Redis can use to restore its state.

```
SAVE
```

Synchronous save of the dataset to disk. When Redis starts the save operation, it blocks all the clients until the save operation is complete. NOT RECOMMENDED IN PROD.

```
BGSAVE
```

Background SAVE or Asynchronous SAVE. This forks a new process, and the child process writes the snapshot to the disk. It is used in Prod as Redis continues to process commands while the snapshot is being created.

**Automation**

```
redis.conf
```

```
save 900 1
```

Saves the datasets every 900 seconds if at least one write operation has occurred.

```
save 300 10
```

Saves the datasets every 300 seconds if at least 10 write operations have occurred.

You can have multiple **SAVE** in redis.conf file for different conditions.

It creates a **dump.rdb** file (it is configurable to different name in redis.conf)

```
dbfilename mybackup.rdb
```

How to load from RDB?

When Redis is restarted, it checks for the RDB file and loads the contents to memory.

2. **AOF (Append Only File)**: This method logs every write operation the server receives, appending each operation to a file. This allows for more granular persistence and more durability than RDB, as you can configure Redis to append data on every write operation at the cost of performance. The AOF file can be replayed to reconstruct the state of the data.

```
# Enable AOF persistence
appendonly yes

# Specify the filename for the AOF file
appendfilename "appendonly.aof"

# Set the fsync policy to balance durability and performance
# 'always' - fsync on every write; most durable but slower
# 'everysec' - fsync every second; good balance (recommended)
# 'no' - rely on OS to decide; fastest but least durable
appendfsync everysec

auto-aof-rewrite-percentage 100 # Rewrite when AOF size
# Automatic rewriting of the AOF file when it grows too big
auto-aof-rewrite-min-size 64mb  # Minimum size for the AOF file to be rewritten
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gchandra.gitbook.io/big-data-and-tools-with-nosql/nosql/redis/persistence.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
