How can you lose data in Redis

Does Redis keep data?

I understand that Redis provides all data from memory, but it persists even after restarting the server so that when the server is restarted, all data is read from the hard drive into memory. Or is it always empty storage just storing data while running apps with no persistence?


I suggest you read this at Basically, if you increase performance by using only in-memory storage, you lose guaranteed persistence. Imagine a scenario where you put INSERT into memory, but you lose power before it stays on disk. Data loss occurs.

Redis supports so-called "snapshots". This means that at certain times (e.g. every hour on the hour) a full copy of the store is made. If you lose power between two snapshots, you will lose the data between the last snapshot and the crash (doesn't have to be a power outage ..). Redis trades data security for performance like most NoSQL DBs do.

Most NoSQL databases follow a multi-node replication concept to minimize this risk. Redis is seen as a fast cache rather than a database that guarantees data consistency. Therefore, the use cases are usually different from those of real databases: for example, you can store sessions, performance counters or whatever in them, with unmatched performance and with no real loss in the event of a crash. However, processing orders / purchase histories etc. is considered a task for traditional databases.

The Redis server stores all of its data on the hard drive from time to time and thus offers a certain degree of persistence.

It stores data in any of the following cases:

  • automatically from time to time
  • if you invoke the command manually
  • when redis shuts down

But data in Redis isn't really persistent because:

  • A crash of the Redis process means that all changes since the last save will be lost
  • The operation can only be performed if you have enough free memory (the amount of additional memory is equal to the size of the Redis database).

NB: The RAM requirement is a real problem as redis keeps working until there is no more RAM to run, but it stops saving data to disk much earlier (at around 50% of RAM).

For more information, see Redis Persistence.

It's a matter of configuration. You may have no, partial, or complete persistence of your data on Redis. The best decision will depend on the technical and business needs of the project.

According to the Redis documentation on persistence, you can set up your instance so that data is saved to disk from time to time or with every query. They offer two strategies / methods AOF and RDB (read the documentation to see details at this point). You can use each one individually or together.

If you want "SQL-like persistence" they said:

The general note is that if you want a level of data security comparable to what PostgreSQL can offer you, you should use both persistence methods.

The answer is in general Yes . A more complete answer, however, depends on what type of data you want to store. In general, the more complete short answer is:

  • Redis isn't best for persistent storage because it's primarily performance biased
  • Redis is better suited for reliable storage / caching more current Status data in memory, especially to enable scalability by providing a central source for data that is used on multiple clients / servers

With that said, it defaults to Redis become Data exist Snapshots at a periodic interval (apparently this every 1 minute, but I haven't checked this - which is described by the article below, which is a good basic intro):


From the official documents:

  • The RDB persistence [Default setting] takes snapshots of your data set at certain times at certain intervals.
  • The AOF persistence [must be configured explicitly] logs every write operation received from the server, which is played again when the server starts, and reconstructs the original dataset.

Redis must explicit for AOF persistence can be configured if necessary. This leads to a decrease in performance as well as growing logs. This may be sufficient for a relatively reliable persistence of a limited amount of data.

You can't choose persistence at all. Better performance but lose all data when Redis shuts down.

Redis has two persistence mechanisms: RDB and AOF.RDB use a global scheduler snapshooting and AOF writes an update to an app-only log file similar to MySql.

You can use either or both. When Redis restarts, data is created from reading the RDB or AOF file.

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.