I am using Redis as more of a temporary store, but there are some fields that I want to persist, so I want to use RDB. A few minutes lost will not hurt. However I am noticing that at times I get big IO Wait spikes on my server and I believe it is when an RDB save is occurring.
I found that there are two commands when running manually, BGSAVE and SAVE. They do the same thing, but BGSAVE allows for background saving to ensure that redis does not block any new writes/reads.
The config file for saving has lines similar to:
save 10 1000
save 100 500
Is this literally meaning that it is using the SAVE command and if so, can I replace that with bgsave and get my expected/needed results?
Redis is very data backup friendly since you can copy RDB files while the database is running: the RDB is never modified once produced, and while it gets produced it uses a temporary name and is renamed into its final destination atomically using rename(2) only when the new snapshot is complete.
Redis BGSAVE command saves the DB in the background. The OK code is immediately returned. Redis forks, the parent continues to serve the clients, the child saves the DB on the disk, then exits. A client may be able to check if the operation succeeded using the LASTSAVE command.
RDB is for Redis Database Backup file. RDB file is a dump of all user data stored in an internal, compressed serialization format at a particular timestamp which is used for point-in-time recovery (recovery from a timestamp).
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.
The configuration's save
directive invokes the same mechanism as BGSAVE
, i.e. it will not block the server. I totally understand, however, why this is confusing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With