rediscentosshutdownpersist

How to shutdown redis safely without data loss


I have written a script which can get really long to run, I save the steps that are passed in the redis because it's fast and has almost no overhead, but a manual reboot or a server downtime could happen in the middle, so if the last step isn't saved the whole process will have to start from the beginning!

Ideally I want to set up redis in a way, that it persists before shutdown, (if this is not already supported by default which I couldn't find anything about it) in the basic way I would need to be able to persist the data with redis-cli or anyway possible via a script, then find a way to run a script before shutdown of CentOS.

So any suggestions would be great.


Solution

  • Redis features different persistence options, including AOF (Append Only File) that

    logs every write operation received by the server, that will be played again at server startup, reconstructing the original dataset

    with the ability to fsync at every query.

    If this is not a viable option for you, you may want to issue a combination of BGSAVE and LASTSAVE commands in order to start an asynchronous saving process and check whether the last saving completed successfully or not.