Redis create a snapshot RDB

What is RDB?
1.Redis data stored in memory, you can create a binary file on your hard disk by rdb save or bgsave. The rdb file is equivalent to a snapshot redis data.
2.Redis after the restart, the hard drive will be loaded into memory rdb file contents.
3.rdb can also copy the file transfer as a medium. As the master copy is redis transmitted by rdb.

RDB is triggered in three ways

A, save command

1.save instruction synchronous snapshot.

Redis commands sent by the client save all data in memory will redis server package, create rdb file on the hard disk and save the data.

2.save synchronous blocking other client requests.

Because redis is single-threaded, when executing the save rdb file is created, it will block the request redis other clients. When rdb created, blocking end.


Two, bgsave command

1.bgsave Asynchronous create a snapshot

The client sends bgsave command, redis server will fork a child process, the child process will redis packed data server memory to the hard drive in the rdb file.

2.bgsave asynchronous non-blocking

redis server during fork child process in a short time will block other client requests (shorter, negligible), the child process is created it will not block the request of other clients. Asynchronous create child process created after the success of rdb file, and sends a signal to the main process after the save is complete, save the notification has been completed. The process will soon fork child process, fork child process consumes additional memory.


Third, the automatic trigger
to create a snapshot of the configuration redis.conf

save 900 1
save 300 10
save 60 10000

Wherein the RDB:
Advantages:
1. for large-scale data recovery, data integrity and consistency of less demanding.

Drawback:
1.redis time lag created rdb snapshot, if re-create a snapshot of downtime last, after the last snapshot modified data will be lost.

2.bgsave operation (included automatically trigger the creation of rdb) created rdb snapshot fork child process copies the data in a memory, it will consume a certain amount of memory.

Dynamic closed automatically creates a snapshot

127.0.0.1:6379>config save ""

View rdb file location

127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/var/lib/redis"

Guess you like

Origin blog.51cto.com/phpme/2455485