In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about the use of Redis persistence RDB. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Redis persistence I, RDB
Purpose: write a snapshot of a dataset in memory to disk within a specified time interval, that is, a Snapshot snapshot. When it resumes, it reads the snapshot file directly into memory.
Principle: Redis will create (fork) a child process separately for persistence, first writing data to the
In a temporary file, the pending persistence process is over, and then replace the last persisted file with this temporary file.
Throughout the process, the main process does not perform any IO operations, which ensures extremely high performance
If large-scale data recovery is required and is not very sensitive to the integrity of data recovery, then the RDB party
Type is more efficient than the AOF method. The disadvantage of RDB is that the data may be lost after the last persistence.
Cons: may lose the last save
Fork: the role of fork is to copy a process that is the same as the current process. The values of all data (variables, environment variables, program counters, etc.) of the new process are the same as those of the original process, but it is a new process and acts as a child of the original process.
Files: Rdb saves dump.rdb files
Configuration: SNAPSHOTTING snapshot
Format: save-> save write operations per second
Default: default trigger condition
Change once in 15 minutes (900 seconds)
Change 10 times in 5 minutes (300 seconds)
Change 10000 times in 1 minute (60 seconds)
Disable: do not set or save ""
2. Case study
Set save 12010 (change 10 times in 120s)
1. Delete the backup file [root@VM_0_7_centos ~] # cd / usr/local/ [root @ VM_0_7_centos bin] # lltotal 37820 dump.rdb-rwxr-xr-x-1 root root 231 Jun 19 18:35 dump.rdb-rwxr-xr-x 1 root root 4739968 Jun 12 23:09 redis-benchmark-rwxr-xr-x 1 root root 9634424 Jun 12 23:09 redis-check-aof-rwxr-xr-x 1 root root 9634424 Jun 12 23:09 redis-check -rdb-rwxr-xr-x 1 root root 5050384 Jun 12 23:09 redis-clilrwxrwxrwx 1 root root 12 Jun 12 23:09 redis-sentinel-> redis-server-rwxr-xr-x 1 root root 9634424 Jun 12 23:09 redis-server-rwxr-xr-x 1 root root 9840 Jun 12 22:55 root root 8.6 [root @ VM_0_7_centos bin] # rm-f dump.drb2. Start the redis service
3. Set the value 127.0.0.1 set 9736 > set K1 v1OK127.0.0.1:9736 > set K2 v2OK127.0.0.1:9736 > set K3 v3OK127.0.0.1:9736 > set K4 v4OK127.0.0.1:9736 > set K5 v5OK127.0.0.1:9736 > set K6 v6OK127.0.0.1:9736 > set K7 v7 OK127.0.0.1:9736 > set K8 v8OK127.0.0.1:9736 > set K9 v9OK127.0.0.1:9736 > set K10 v10 OK127.0.0 .1 set 9736 > set K11 v11OK127.0.0.1:9736 > set K12 v12OK127.0.0.1:9736 > set K13 v134. Backup
[root@VM_0_7_centos bin] # cp dump.rdb dump-bk.rdb
[root@VM_0_7_centos bin] # lltotal 37824 Sep-1 root root 275 Sep 23 10:48 dump-bk.rdb-rw-r--r-- 1 root root 275 Sep 23 10:43 dump.rdb-rwxr-xr-x 1 root root 4739968 Jun 12 23:09 redis-benchmark-rwxr-xr-x 1 root root 9634424 Jun 12 23:09 redis-check-aof-rwxr-xr-x 1 root root 9634424 Jun 12 23:09 redis-check- Rdb-rwxr-xr-x 1 root root 5050384 Jun 12 23:09 redis-clilrwxrwxrwx 1 root root 12 Jun 12 23:09 redis-sentinel-> redis-server-rwxr-xr-x 1 root root 9634424 Jun 12 23:09 redis-server-rwxr-xr-x 1 root root 9840 Jun 12 22:55 tclsh8.65. Delete message 127.0.0.1 empty array 9736 > FLUSHALLOK127.0.0.1:9736 > keys * (empty array) 127.0.1 empty array 9736 > SHUTDOWNnot connected > exit [root @ VM_0_7_centos bin] # 6. Reconnect to view the content 127.0.0.1 9736 > keys * (empty array)
Note: FLUSHALL SAVE or SHUTDOWN will quickly save memory data to dump.rdb
7. Shutdown exit8. Restore the backed up file [root@VM_0_7_centos bin] # rm-f dump.rdb[ root @ VM_0_7_centos bin] # cp dump-bk.rdb dump.rdb9. View the recovered message 127.0.0.1 list01 9736 > keys * 1) "K1" 2) "K3" 3) "K4" 4) "user" 5) "K2" 6) "list01" 7) "K8" 8) "K10" 9) "K6" 10) "K9" 11) "K7" 12) "list02" 13) "K5" 10. Back up the command save in time. Other configuration
Stop-writes-on-bgsave-error yes: stop saving if there is a save error
If no is configured to indicate that you don't care about data inconsistencies or other means of discovery and control,
Rdbcompression: for snapshots stored on disk, you can set whether to compress or not. If so, redis uses the LZF algorithm for compression. If you do not want to consume CPU for compression, you can set this feature to off. Yes is enabled by default.
Rdbchecksum: after storing the snapshot, you can also have redis use the CRC64 algorithm for data validation, but doing so will increase the performance consumption by about 10%. If you want to get the maximum performance improvement, you can turn this feature off.
Dbfilename dump.rdb: backup file name
Dir. /: specify the local database storage directory
4. Key 12. How to trigger a RDB snapshot
12.1 default snapshot configuration in the configuration file, which can be reused after cold copy and can be cp dump.rdb dump_new.rdb
12.2 Command save or bgsave
Just save it when you Save:save, do not care about anything else, and block it all
BGSAVE:Redis performs snapshot operations asynchronously in the background, and snapshot operations can also respond to client requests. The time of the last successful snapshot can be obtained through the lastsave command.
Executing the flushall command will also generate a dump.rdb file, but it is empty and meaningless.
13. How to recover
Move the backup file (dump.rdb) to the redis installation directory and start the service, and CONFIG GET dir gets the directory
14. advantage
Suitable for large-scale data recovery with low requirements for data integrity and consistency
15. Inferior position
Make a backup at regular intervals, so if redis accidentally down, it will lose all the changes after the last snapshot. During fork, a copy of the data in memory is cloned, and roughly twice the expansibility needs to be considered.
16. How to stop
Dynamic all methods to stop RDB saving rules: redis-cli config set save ""
17. Small summary
Thank you for reading! This is the end of this article on "what is the use of Redis persistence RDB?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.