Redis data persistence


#1

I am currently using redis in my project. However, sometimes all the data is lost when the app restarts. The redis is stored in .data/redis-stable/ folder. Is this intended or is there some configuration I could do to ensure data persistence?


#2

The file system is persistent by default, there’s no configuration required. What happens when the data is lost, is the database file empty or no longer exists?


#3

Sorry if i’m being random but, how did you installed redis on glitch @Andy-William?


#4

@Gareth I’m not sure where redis saves the database file, but the data is gone. All keys return empty value.

So far the data loss never happens when it restarts because I’m coding, but rather on other random time of the day (when I assume glitch updates so all projects got restarted).

@NikoBotDev
running the following command on .data

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

source: https://redis.io/topics/quickstart


#5

Read about how to configure Redis persistence in the Redis documentation.

From redis-cli, you can check if persistence is enabled using CONFIG GET save and CONFIG GET appendonly.

You can check where the RDB is stored using CONFIG GET dbfilename, and the AOF log CONFIG GET appendfilename.

When following the steps you wrote above and start the server with .data/redis-stable/src/redis-server &, I see the following output on .data/redis-stable/src/redis-cli:

127.0.0.1:6379> CONFIG GET save
1) "save"
2) "3600 1 300 100 60 10000"
127.0.0.1:6379> CONFIG GET dbfilename
1) "dbfilename"
2) "dump.rdb"
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> CONFIG GET appendfilename
(empty list or set)

This output means that Redis will save a dump file to .data/redis-stable/dump.rdb every hour there is a write, every 5 minutes if there have been at least 100 writes, and every minute if there have been at least 10000 writes. (If the Redis server is cleanly shut down, it will also write a dump file.) However, if there hasn’t been a write in a while and your container is shut down, Redis won’t get the chance to write its dump file, and you will lose data.

My recommendation is to turn on appendonly, so that your data is written to disk almost as soon as it can be. You’ll be much less likely to lose any data this way.


#6

It turns out my config file wasn’t loaded to the server :sweat_smile:

It now properly loads and I changed to AOF also. The file is saved in /app/appendfile.aof though, so I think I need to change it to somewhere in .data.

Anyway, thank you for your help.