Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Redis to persist data after reboot on Linux?

I installed Redis on Ubuntu 16.04. I couldn't find Redis directory nor redis.conf file (tried with: sudo find redis.conf).

My application depends on some data pulled from third party APIs. I store the (processed) data in Redis. My problem is, after reboot I lose the data. I guess I need to specify in config file that the data should be persisted on reboot, but I couldn't find the config file. Do I need to create the config file? Are there some templates to use? My goal is just to have the data persisted after reboot.

Thank you!

like image 957
giliev Avatar asked May 14 '17 21:05

giliev


People also ask

How do I make Redis persistent?

Within Redis, there are two different ways of persisting data to disk. One is a method called snapshotting that takes the data as it exists at one moment in time and writes it to disk. The other method is called AOF, or append—only file, and it works by copying incoming write commands to disk as they happen.

Does Redis persist data on restart?

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.

Which is the default persistence mode in Redis?

As previously stated, snapshotting is the default persistence mode for Redis. It asynchronously performs a full dump of your database to disk, overwriting the previous dump only if successful. Therefore, the latest dump should always be in your dbfilename location.

Can I use Redis as persistent database?

No persistence: Redis can be entirely ephemeral with no persistence at all. Our data is only available while the server is running, and if for some reason the server was terminated or rebooted our data is lost.


2 Answers

Use dpkg -L redis-server | grep redis.conf to find config file path. It should be located at /etc/redis/redis.conf as I know.

Redis has 2 methods for persistense: Snapshotting and Append-only file:

  • Snapshotting will be enabled by adding (or uncommenting) save X Y in config file. It means Redis will automatically dump the dataset to disk every X seconds if at least Y keys changed. There could be more than one save options in config file.

  • Append-only file will be enabled by adding (or uncommenting) appendonly yes in config file

like image 174
Seyed Mehran Siadati Avatar answered Oct 26 '22 23:10

Seyed Mehran Siadati


you should turn on the rdb or aof.

see https://redis.io/topics/persistence

like image 23
Mobility Avatar answered Oct 26 '22 23:10

Mobility