0
0
Redisquery~5 mins

Why persistence matters in Redis

Choose your learning style9 modes available
Introduction

Persistence means saving your data so it is not lost when the system restarts or crashes. It helps keep your important information safe and available.

You want to keep user sessions even if the server restarts.
You need to save shopping cart items so customers don't lose them.
You want to store game scores that should not disappear after a crash.
You need to keep configuration settings that must survive restarts.
You want to log events and keep them for later analysis.
Syntax
Redis
redis.conf settings for persistence:
save 900 1
save 300 10
save 60 10000
appendonly yes

save lines tell Redis when to save data to disk automatically.

appendonly yes enables a log to record every change for better durability.

Examples
Save the database if at least 1 key changed in 900 seconds (15 minutes).
Redis
save 900 1
Save the database if at least 10 keys changed in 300 seconds (5 minutes).
Redis
save 300 10
Turn on the append-only file to log every write operation for better data safety.
Redis
appendonly yes
Sample Program

This example sets a value, forces Redis to save data to disk, then retrieves the value to show it is stored.

Redis
127.0.0.1:6379> SET user:1 "Alice"
OK
127.0.0.1:6379> SAVE
OK
127.0.0.1:6379> GET user:1
"Alice"
OutputSuccess
Important Notes

Without persistence, all data is lost if Redis restarts or crashes.

Persistence can slow down performance slightly but keeps data safe.

Redis offers two persistence methods: RDB snapshots and AOF logs; you can use one or both.

Summary

Persistence saves your data to disk to prevent loss.

It is important for keeping user data, settings, and logs safe.

Redis uses configuration settings to control how and when data is saved.