Redis is a qualified Java development engineer must master the knowledge, fox will write down their own understanding, this article only represents my summary and understanding, if there are mistakes, welcome to correct…

1. What is RDB

RDB: Periodically writes data in the memory to a temporary file on a disk. The snapshot file is used as a snapshot file and read into the memory during recovery. If redis is restarted, the data in the memory will not be restored.

2. Backup and restoration

Memory backup –> Temporary files on disk

Temporary files –> Restore to memory

3. Advantages and disadvantages of RDB

advantage

  1. Make full backups every once in a while

  2. Dr Is simple and can be transmitted remotely

  3. When the child process backs up data, the master process does not perform any I/O operations (write, modify, or delete) to ensure the integrity of backup data

  4. Compared to AOF, it can be restarted quickly when there are larger files

disadvantage

  1. If a fault occurs, the last backup data may be lost

  2. The child process will use exactly the same memory ratio as the parent process, resulting in CPU burden

  3. Because scheduled full backup is a heavyweight operation, real-time backup cannot be handled.

4. Configure the RDB

  1. Save location can be customized in redis.conf:

/user/local/redis/working/dump.rdb

  1. Saving mechanism:

save 900 1 save 300 10 save 60 10000 save 10 3

  • If 1 cache is updated, backup takes 15 minutes
  • If 10 caches are updated, then 5 minutes backup
  • If 10000 cache updates, 1 minute backup
  • Demo: Update 3 caches, 10 second backups
  • Demo: Backup dump. RDB, delete and restart
  1. stop-writes-on-bgsave-error

Yes: Stop the write operation if the save process fails

No: Data inconsistency may occur

  1. rdbcompression

Yes: Enable the RDB compression mode

No: close the file, which will save CPU consumption, but the file will be large, similar to nginx

  1. rdbchecksum

What is AOF?

RDB will lose the last backup RDB file, but in fact, it doesn’t matter, in fact, can be ignored, after all, it is cache, lost, but if you want to pursue data integrity, then consider using AOF

AOF characteristics

  1. Write operations requested by users are recorded in logs. Read operations are not recorded, because write operations are stored.

  2. Files are appended rather than modified.

  3. Redis aOF recovery is actually to read the appended file from start to end to perform write operations.

advantage

  1. AOF is more durable and can be backed up in seconds. If a problem occurs, only the last second of data will be lost, greatly increasing reliability and data integrity. So AOF can be backed up once per second, using fsync operations.

  2. If the disk is full, the redis-check-aof tool is executed

  3. Redis can automatically override aOF in the background when the data is too large. While Redis continues appending logs to old files, overwriting is also safe and does not affect client read and write operations.

  4. AOF logs contain all writes, which makes redis parsing recovery easier.

disadvantage

  1. Same data, same data, AOF is greater than RDB

  2. For different synchronization mechanisms, AOF is slower than RDB because AOF backs up writes every second, which is slightly lower than RDB. There is nothing wrong with backing up fsync every second, but redis performance will deteriorate if the client backs up fsync every time it writes.

  3. AOF has had a bug, that is, incomplete data during data recovery. In this way, AOF will be fragile and prone to bugs, because AOF is not as simple as RDB. However, in order to prevent bugs, AOF will not reconstruct according to the old instructions, but according to the data instructions in the cache at that time. It’s much more robust and reliable.

RDB or AOF?

  1. If you can live with cache loss for a period of time, use RDB

  2. If you care about real-time data, use AOF


Conclusion: Ever is to learn to read people’s blog technology, some of them have essence blog also have to play around the CV of solution, so the decided to study the knowledge sharing for everyone, mainly want to go to the sea after less detours, more positive energy blog, if there are any errors, welcome to point out mistakes, only hope that we can learn knowledge in my blog, Solve the problem, then it is enough. Thank you! (Please note the original source for reprint)