Does Redis persist data?

2019-03-08 17:06发布

I understand that Redis serves all data from memory, but does it persist as well across server reboot so that when the server reboots it reads into memory all the data from disk. Or is it always a blank store which is only to store data while apps are running with no persistence?

标签: redis
4条回答
Juvenile、少年°
2楼-- · 2019-03-08 17:37

It is a matter of configuration. You can have none, partial or full persistence of your data on Redis. The best decision will be driven by the project's technical and business needs.

According to the Redis documentation about persistence you can set up your instance to save data into disk from time to time or on each query, in a nutshell. They provide two strategies/methods AOF and RDB (read the documentation to see details about then), you can use each one alone or together.

If you want a "SQL like persistence", they have said:

The general indication is that you should use both persistence methods if you want a degree of data safety comparable to what PostgreSQL can provide you.

查看更多
干净又极端
3楼-- · 2019-03-08 17:40

You can choose no persistence at all.Better performance but all the data lose when Redis shutting down.

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

You can use one of them or both.When Redis reboots,it constructes data from reading the RDB file or AOF file.

查看更多
Anthone
4楼-- · 2019-03-08 17:56

I suggest you read about this on http://redis.io/topics/persistence . Basically you lose the guaranteed persistence when you increase performance by using only in-memory storing. Imagine a scenario where you INSERT into memory, but before it gets persisted to disk lose power. There will be data loss.

Redis supports so-called "snapshots". This means that it will do a complete copy of whats in memory at some points in time (e.g. every full hour). When you lose power between two snapshots, you will lose the data from the time between the last snapshot and the crash (doesn't have to be a power outage..). Redis trades data safety versus performance, like most NoSQL-DBs do.

Most NoSQL-databases follow a concept of replication among multiple nodes to minimize this risk. Redis is considered more a speedy cache instead of a database that guarantees data consistency. Therefore its use cases typically differ from those of real databases: You can, for example, store sessions, performance counters or whatever in it with unmatched performance and no real loss in case of a crash. But processing orders/purchase histories and so on is considered a job for traditional databases.

查看更多
唯我独甜
5楼-- · 2019-03-08 18:02

Redis server saves all its data to HDD from time to time, thus providing some level of persistence.

It saved data in one of the following cases:

  • automatically from time to time
  • when you manually call BGSAVE command
  • when redis is shutting down

But data in redis is not really persistent, because:

  • crash of redis process means losing all changes since last save
  • BGSAVE operation can only be performed if you have enough free RAM (the amount of extra RAM is equal to the size of redis DB)

N.B.: BGSAVE RAM requirement is a real problem, because redis continues to work up until there is no more RAM to run in, but it stops saving data to HDD much earlier (at approx. 50% of RAM).

For more information see Redis Persistence.

查看更多
登录 后发表回答