How to configure Redis to persist data after reboot on Linux?
Asked Answered
R

3

9

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!

Revulsion answered 14/5, 2017 at 21:12 Comment(0)
B
9

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

Bartko answered 10/2, 2018 at 8:56 Comment(3)
I didn't do any of these changes but my keys were still there even after a redis-server restart, why?? @seyedHemichordate
@AATHITHRAJENDRAN Three 'save' commands are enabled by default in 'redis.conf', so it's normal behavior.Bartko
thanks, by default they already have 3 save command for us, so the point of snapshotting could be pass (or you can modify as you want), now just need to enable appendonly yes will make redis to be persistent.Annunciate
G
5

you should turn on the rdb or aof.

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

Guberniya answered 15/5, 2017 at 1:50 Comment(0)
C
0

Add this to the config file.

appendonly yes

This will append data as you store new data. This enables durability.

Celiotomy answered 15/5, 2017 at 6:58 Comment(3)
Do I need to create the config file? I couldn't find in my file system a file named redis.conf.Revulsion
config file is present by default. just edit it. path of config file : redis-server /etc/redis.confCeliotomy
This will enable aof persistence which may or may not be the mode you want. Depending on your durability and performance needs you may want to use RDB persistence.Alrick

© 2022 - 2024 — McMap. All rights reserved.