{"id":136058,"date":"2019-02-18T10:43:57","date_gmt":"2019-02-18T02:43:57","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=136058"},"modified":"2019-02-18T09:46:08","modified_gmt":"2019-02-18T01:46:08","slug":"redis-rdb-aof","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redis-rdb-aof.html","title":{"rendered":"\u914d\u7f6e\u65b9\u6848\uff1aRedis\u6301\u4e45\u5316RDB\u548cAOF"},"content":{"rendered":"
Redis\u6301\u4e45\u5316\u65b9\u6848<\/strong><\/div>\n

Redis\u662f\u5185\u5b58\u6570\u636e\u5e93\uff0c\u6570\u636e\u90fd\u662f\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u4e3a\u4e86\u907f\u514d\u8fdb\u7a0b\u9000\u51fa\u5bfc\u81f4\u6570\u636e\u7684\u6c38\u4e45\u4e22\u5931\uff0c\u9700\u8981\u5b9a\u671f\u5c06Redis\u4e2d\u7684\u6570\u636e\u4ee5\u67d0\u79cd\u5f62\u5f0f\uff08\u6570\u636e\u6216\u547d\u4ee4\uff09\u4ece\u5185\u5b58\u4fdd\u5b58\u5230\u786c\u76d8\u3002\u5f53\u4e0b\u6b21Redis\u91cd\u542f\u65f6\uff0c\u5229\u7528\u6301\u4e45\u5316\u6587\u4ef6\u5b9e\u73b0\u6570\u636e\u6062\u590d\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u4e3a\u4e86\u8fdb\u884c\u707e\u96be\u5907\u4efd\uff0c\u53ef\u4ee5\u5c06\u6301\u4e45\u5316\u6587\u4ef6\u62f7\u8d1d\u5230\u4e00\u4e2a\u8fdc\u7a0b\u4f4d\u7f6e\u3002<\/p>\n

Redis\u63d0\u4f9b\u4e86\u591a\u79cd\u4e0d\u540c\u7ea7\u522b\u7684\u6301\u4e45\u5316\u65b9\u5f0f\uff1a\u4e00\u79cd\u662fRDB\uff0c\u53e6\u4e00\u79cd\u662fAOF\u3002<\/p>\n

RDB\u6301\u4e45\u5316\u53ef\u4ee5\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5185\u751f\u6210\u6570\u636e\u96c6\u7684\u65f6\u95f4\u70b9\u5feb\u7167\uff08point-in-time snapshot\uff09\uff0c\u5c06\u6570\u636e\u5e93\u7684\u5feb\u7167\uff08snapshot\uff09\u4ee5\u4e8c\u8fdb\u5236\u7684\u65b9\u5f0f\u4fdd\u5b58\u5230\u78c1\u76d8\u4e2d\u3002<\/p>\n

AOF\u6301\u4e45\u5316\u8bb0\u5f55\u670d\u52a1\u5668\u6267\u884c\u7684\u6240\u6709\u66f4\u6539\u64cd\u4f5c\u547d\u4ee4\uff0cAOF\u6587\u4ef6\u4e2d\u7684\u547d\u4ee4\u5168\u90e8\u4ee5Redis\u534f\u8bae\u7684\u683c\u5f0f\u6765\u4fdd\u5b58\uff0c\u65b0\u547d\u4ee4\u4f1a\u88ab\u8ffd\u52a0\u5230\u6587\u4ef6\u7684\u672b\u5c3e\u3002Redis\u8fd8\u53ef\u4ee5\u5728\u540e\u53f0\u5bf9AOF\u6587\u4ef6\u8fdb\u884c\u91cd\u5199\uff08rewrite\uff09\uff0c\u4f7f\u5f97AOF\u6587\u4ef6\u7684\u4f53\u79ef\u4e0d\u4f1a\u8d85\u51fa\u4fdd\u5b58\u6570\u636e\u96c6\u72b6\u6001\u6240\u9700\u7684\u5b9e\u9645\u5927\u5c0f\u3002<\/p>\n

Redis\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528AOF\u6301\u4e45\u5316\u548cRDB\u6301\u4e45\u5316\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5f53Redis\u91cd\u542f\u65f6\uff0c\u5b83\u4f1a\u4f18\u5148\u4f7f\u7528AOF\u6587\u4ef6\u6765\u8fd8\u539f\u6570\u636e\u96c6\uff0c\u56e0\u4e3aAOF\u6587\u4ef6\u4fdd\u5b58\u7684\u6570\u636e\u96c6\u901a\u5e38\u6bd4RDB\u6587\u4ef6\u6240\u4fdd\u5b58\u7684\u6570\u636e\u96c6\u66f4\u5b8c\u6574\u3002\u4f60\u751a\u81f3\u53ef\u4ee5\u5173\u95ed\u6301\u4e45\u5316\u529f\u80fd\uff0c\u8ba9\u6570\u636e\u53ea\u5728\u670d\u52a1\u5668\u8fd0\u884c\u65f6\u5b58\u5728\u3002<\/p>\n

\u4e86\u89e3RDB\u6301\u4e45\u5316\u548cAOF\u6301\u4e45\u5316\u4e4b\u95f4\u7684\u5f02\u540c\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u4ee5\u4e0b\u51e0\u4e2a\u5c0f\u8282\u5c06\u8be6\u7ec6\u5730\u4ecb\u7ecd\u8fd9\u8fd9\u4e24\u79cd\u6301\u4e45\u5316\u529f\u80fd\uff0c\u5e76\u5bf9\u5b83\u4eec\u7684\u76f8\u540c\u548c\u4e0d\u540c\u4e4b\u5904\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n

RDB\u5feb\u7167<\/strong><\/div>\n

\u4e0b\u9762\u6211\u4eec\u8bf4\u4e00\u4e0bRedis\u7684\u7b2c\u4e00\u4e2a\u6301\u4e45\u5316\u7b56\u7565\uff0cRDB\u5feb\u7167\u3002Redis\u652f\u6301\u5c06\u5f53\u524d\u5185\u5b58\u6570\u636e\u7684\u5feb\u7167\u5b58\u6210\u4e00\u4e2a\u6570\u636e\u6587\u4ef6\u7684\u6301\u4e45\u5316\u673a\u5236\uff0c\u800c\u4e00\u4e2a\u6301\u7eed\u5199\u5165\u7684\u6570\u636e\u5e93\u5982\u4f55\u751f\u6210\u5feb\u7167\u5462\uff1fRedis\u5de7\u5999\u5730\u501f\u52a9\u4e86fork\u547d\u4ee4\u7684\u5199\u65f6\u590d\u5236\uff08copy on write\uff09\u673a\u5236\uff0c\u5c06\u5f53\u524d\u8fdb\u7a0bfork\u51fa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u5b50\u8fdb\u7a0b\u6839\u636e\u5185\u5b58\u5feb\u7167\uff0c\u5faa\u73af\u5c06\u6570\u636e\u6301\u4e45\u5316\u4e3aRDB\u6587\u4ef6\u3002<\/p>\n

\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c Redis\u5c06\u6570\u636e\u5e93\u5feb\u7167\u4fdd\u5b58\u5728\u6839\u76ee\u5f55\u4e0b\uff0c\u540d\u5b57\u4e3adump.rdb\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\u3002\u53ef\u901a\u8fc7\u53c2\u6570dir\u914d\u7f6e\u6307\u5b9a\u4fdd\u5b58\u76ee\u5f55\uff0cdbfilename\u6307\u5b9a\u6587\u4ef6\u540d\u3002\u4f60\u53ef\u4ee5\u5bf9Redis\u8fdb\u884c\u8bbe\u7f6e\uff0c\u5982\u201csave N M\u201d\uff0c\u8868\u793aN\u79d2\u5185\u6570\u636e\u9879\u4e2d\u6709M\u4e2a\u6539\u52a8\u65f6\u8fd9\u4e00\u6761\u4ef6\u88ab\u6ee1\u8db3\u65f6\uff0c\u81ea\u52a8\u4fdd\u5b58\u4e00\u6b21\u6570\u636e\u96c6\u3002\u6bd4\u5982\u4f60\u53ef\u4ee5\u914d\u7f6e\u5f5310\u5206\u949f\u4ee5\u5185\u6709100\u6b21\u5199\u5165\u5c31\u751f\u6210\u5feb\u7167\uff0c\u4e5f\u53ef\u4ee5\u914d\u7f6e\u5f531\u5206\u949f\u5185\u67091000\u6b21\u5199\u5165\u5c31\u751f\u6210\u5feb\u7167\uff0c\u652f\u6301\u53ef\u4ee5\u591a\u4e2a\u89c4\u5219\u4e00\u8d77\u751f\u6548\uff0c\u5f53\u5339\u914d\u5230\u54ea\u4e2a\u5c31\u54ea\u4e2a\u89c4\u5219\u751f\u6548\u3002\u8fd9\u4e9b\u89c4\u5219\u7684\u5b9a\u4e49\u5c31\u5728Redis\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7Redis\u7684CONFIG SET\u547d\u4ee4\u5728Redis\u8fd0\u884c\u65f6\u8bbe\u7f6e\u89c4\u5219\uff0c\u4e0d\u9700\u8981\u91cd\u542fRedis\u3002<\/p>\n

\u6bd4\u5982\u8bf4\uff0c\u4ee5\u4e0b\u8bbe\u7f6e\u4f1a\u8ba9Redis\u5728\u6ee1\u8db3\u201c60\u79d2\u5185\u6709\u81f3\u5c11\u67091000\u4e2a\u952e\u88ab\u6539\u52a8\u201d\u8fd9\u4e00\u6761\u4ef6\u65f6\uff0c\u81ea\u52a8\u4fdd\u5b58\u4e00\u6b21\u6570\u636e\u96c6\uff1a<\/p>\n

\r\nsave 60 1000\r\n<\/pre>\n

\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528SAVE\u6216\u8005BGSAVE\uff0c\u624b\u52a8\u8ba9Redis\u8fdb\u884c\u6570\u636e\u96c6\u4fdd\u5b58\u64cd\u4f5c\u3002SAVE\u547d\u4ee4\u6267\u884c\u4e00\u4e2a\u540c\u6b65\u64cd\u4f5c\uff0c\u4ee5RDB\u6587\u4ef6\u7684\u65b9\u5f0f\u4fdd\u5b58\u6240\u6709\u6570\u636e\u7684\u5feb\u7167\uff0c\u5f88\u5c11\u5728\u751f\u4ea7\u73af\u5883\u76f4\u63a5\u4f7f\u7528SAVE\u547d\u4ee4\uff0c\u56e0\u4e3a\u5b83\u4f1a\u963b\u585e\u6240\u6709\u7684\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\uff0c\u4e0d\u8981\u5728\u751f\u4ea7\u73af\u5883\u4f7f\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528BGSAVE\u547d\u4ee4\u4ee3\u66ff\u3002BGSAVE\u547d\u4ee4\u6267\u884c\u8fc7\u7a0b\u4e2d\u662f\u901a\u8fc7fork\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6765\u5b8c\u6210\u7684\uff0c\u6240\u4ee5\u4e0d\u4f1a\u963b\u585e\u5ba2\u6237\u7aef\u8bf7\u6c42\uff0c\u53ea\u6709fork\u5b50\u8fdb\u7a0b\u65f6\u4f1a\u963b\u585e\u670d\u52a1\u5668\u3002\u53e6\u5916\uff0c\u5728\u81ea\u52a8\u89e6\u53d1RDB\u6301\u4e45\u5316\u65f6\uff0cRedis\u4e5f\u4f1a\u9009\u62e9BGSAVE\u800c\u4e0d\u662fSAVE\u6765\u8fdb\u884c\u6301\u4e45\u5316\u3002<\/p>\n

Redis\u81ea\u52a8RDB\u6301\u4e45\u5316\u5728\u5176\u5185\u90e8\u662f\u901a\u8fc7serverCron\u5468\u671f\u6027\u64cd\u4f5c\u51fd\u6570\u3001dirty\u8ba1\u6570\u5668\u3001\u548clastsave\u65f6\u95f4\u6233\u6765\u5b9e\u73b0\u7684\u3002\u5176\u4e2dserverCron\u6bcf100ms\u6267\u884c\u4e00\u6b21\uff0c\u68c0\u67e5\u670d\u52a1\u5668\u72b6\u6001\uff0c\u5176\u4e2d\u5c31\u5305\u62ec\u68c0\u67e5\u201csave N M\u201d\u662f\u5426\u6ee1\u8db3\u6761\u4ef6\uff0c\u5982\u679c\u6ee1\u8db3\u5c31\u6267\u884cBGSAVE\uff1b\u5f53\u7136\u4e5f\u5305\u62ecAOF\u91cd\u5199\u68c0\u67e5\u3002dirty\u8ba1\u6570\u5668\u662fRedis\u670d\u52a1\u5668\u7ef4\u6301\u7684\u4e00\u4e2a\u72b6\u6001\uff0c\u8bb0\u5f55\u4e86\u4e0a\u4e00\u6b21\u6267\u884cBGSAVE\/SAVE\u547d\u4ee4\u540e\uff0c\u670d\u52a1\u5668\u72b6\u6001\u8fdb\u884c\u4e86\u591a\u5c11\u6b21\u4fee\u6539(\u5305\u62ec\u589e\u5220\u6539)\uff0c\u800c\u5f53BGSAVE\/SAVE\u6267\u884c\u5b8c\u6210\u540e\uff0c\u4f1a\u5c06dirty\u91cd\u65b0\u7f6e\u4e3a0\u3002lastsave\u65f6\u95f4\u6233\u4e5f\u662fRedis\u670d\u52a1\u5668\u7ef4\u6301\u7684\u4e00\u4e2a\u72b6\u6001\uff0c\u8bb0\u5f55\u7684\u662f\u4e0a\u4e00\u6b21\u6210\u529f\u6267\u884cBGSAVE\/SAVE\u7684\u65f6\u95f4\uff0c\u5f53\u524d\u65f6\u95f4\u51cf\u53bblastsave\u9700\u6ee1\u8db3M\u3002<\/p>\n

\u9664\u4e86\u624b\u52a8\u548c\u81ea\u52a8\u4ee5\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u60c5\u51b5\u4f1a\u89e6\u53d1BGSAVE\uff1a<\/p>\n

\u5728\u4e3b\u4ece\u590d\u5236\u573a\u666f\u4e0b\uff0c\u5982\u679c\u4ece\u8282\u70b9\u6267\u884c\u5168\u91cf\u590d\u5236\u64cd\u4f5c\uff0c\u5219\u4e3b\u8282\u70b9\u4f1a\u6267\u884cBGSAVE\u547d\u4ee4\uff0c\u5e76\u5c06rdb\u6587\u4ef6\u53d1\u9001\u7ed9\u4ece\u8282\u70b9\u3002
\n\u6267\u884cshutdown\u547d\u4ee4\u65f6\uff0c\u81ea\u52a8\u6267\u884crdb\u6301\u4e45\u5316\u3002
\n\u53e6\u5916\u9700\u8981\u4e86\u89e3\u7684\uff0c\u56e0\u4e3a\u5176\u5199\u64cd\u4f5c\u662f\u5728\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u4e2d\u8fdb\u884c\u7684\uff0c\u5f53\u751f\u6210\u4e00\u4e2a\u65b0\u7684RDB\u6587\u4ef6\u65f6\uff0cRedis\u751f\u6210\u7684\u5b50\u8fdb\u7a0b\u4f1a\u5148\u5c06\u6570\u636e\u5199\u5230\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u901a\u8fc7\u539f\u5b50\u6027rename\u7cfb\u7edf\u8c03\u7528\u5c06\u4e34\u65f6\u6587\u4ef6\u91cd\u547d\u540d\u4e3aRDB\u6587\u4ef6\uff0c\u8fd9\u6837\u5728\u4efb\u4f55\u65f6\u5019\u51fa\u73b0\u6545\u969c\uff0cRedis\u7684RDB\u6587\u4ef6\u90fd\u603b\u662f\u53ef\u7528\u7684\u3002<\/p>\n

\u8fd9\u79cd\u6301\u4e45\u5316\u65b9\u5f0f\u88ab\u79f0\u4e3a\u5feb\u7167\uff08snapshot\uff09\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u660e\u663e\u7684\u770b\u5230\uff0cRDB\u6709\u4ed6\u7684\u4e0d\u8db3\uff0c\u5c31\u662f\u4e00\u65e6\u6570\u636e\u5e93\u51fa\u73b0\u95ee\u9898\uff0c\u90a3\u4e48\u6211\u4eec\u7684RDB\u6587\u4ef6\u4e2d\u4fdd\u5b58\u7684\u6570\u636e\u5e76\u4e0d\u662f\u5168\u65b0\u7684\uff0c\u4ece\u4e0a\u6b21RDB\u6587\u4ef6\u751f\u6210\u5230Redis\u505c\u673a\u8fd9\u6bb5\u65f6\u95f4\u7684\u6570\u636e\u5168\u90e8\u4e22\u6389\u4e86\u3002\u5728\u67d0\u4e9b\u4e1a\u52a1\u4e0b\uff0c\u5982\u679c\u53ef\u4ee5\u5fcd\u53d7\u95f4\u9694\u5185\u6570\u636e\u4e22\u5931\uff0c\u6211\u4eec\u4e5f\u63a8\u8350\u8fd9\u4e9b\u4e1a\u52a1\u4f7f\u7528RDB\u7684\u65b9\u5f0f\u8fdb\u884c\u6301\u4e45\u5316\uff0c\u56e0\u4e3a\u5f00\u542fRDB\u7684\u4ee3\u4ef7\u5e76\u4e0d\u9ad8\u3002\u4f46\u662f\u5bf9\u4e8e\u53e6\u5916\u4e00\u4e9b\u5bf9\u6570\u636e\u5b89\u5168\u6027\u8981\u6c42\u6781\u9ad8\u7684\u5e94\u7528\uff0c\u65e0\u6cd5\u5bb9\u5fcd\u6570\u636e\u4e22\u5931\u7684\u5e94\u7528\uff0cRDB\u5c31\u65e0\u80fd\u4e3a\u529b\u4e86\uff0c\u6240\u4ee5Redis\u5f15\u5165\u4e86\u53e6\u4e00\u4e2a\u91cd\u8981\u7684\u6301\u4e45\u5316\u673a\u5236\uff0cAOF\u65e5\u5fd7\u65b9\u5f0f\u6301\u4e45\u5316\u3002<\/p>\n

\u4e3a\u4e86\u5c3d\u53ef\u80fd\u4f7fRDB\u6587\u4ef6\u4f53\u79ef\u51cf\u5c0f\uff0cRedis\u9ed8\u8ba4\u91c7\u7528LZF\u7b97\u6cd5\u5bf9RDB\u6587\u4ef6\u8fdb\u884c\u538b\u7f29\u3002\u867d\u7136\u538b\u7f29\u8017\u65f6\uff0c\u4f46\u662f\u53ef\u4ee5\u5927\u5927\u51cf\u5c0fRDB\u6587\u4ef6\u7684\u4f53\u79ef\uff0c\u56e0\u6b64\u538b\u7f29\u9ed8\u8ba4\u5f00\u542f\uff0c\u53c2\u6570\u4e3ardbcompression\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cRDB\u6587\u4ef6\u7684\u538b\u7f29\u5e76\u4e0d\u662f\u9488\u5bf9\u6574\u4e2a\u6587\u4ef6\u8fdb\u884c\u7684\uff0c\u800c\u662f\u5bf9\u6570\u636e\u5e93\u4e2d\u7684\u5b57\u7b26\u4e32\u8fdb\u884c\u7684\uff0c\u4e14\u53ea\u6709\u5728\u5b57\u7b26\u4e32\u8fbe\u5230\u4e00\u5b9a\u957f\u5ea6(20\u5b57\u8282)\u65f6\u624d\u4f1a\u8fdb\u884c\u3002<\/p>\n

\u9664\u4e86\u538b\u7f29\uff0c\u4f60\u4e5f\u53ef\u4ee5\u68c0\u9a8cRDB\u6587\u4ef6\uff0c\u901a\u8fc7\u53c2\u6570rdbchecksum\u8bbe\u7f6e\uff0c\u9ed8\u8ba4\u4e3ayes\u3002\u5728\u5199\u5165\u6587\u4ef6\u548c\u8bfb\u53d6\u6587\u4ef6\u65f6\u90fd\u8d77\u4f5c\u7528\uff0c\u5173\u95edchecksum\u5728\u5199\u5165\u6587\u4ef6\u548c\u542f\u52a8\u6587\u4ef6\u65f6\u5927\u7ea6\u80fd\u5e26\u676510%\u7684\u6027\u80fd\u63d0\u5347\uff0c\u4f46\u662f\u6570\u636e\u635f\u574f\u65f6\u65e0\u6cd5\u53d1\u73b0\u3002<\/p>\n

\u53e6\u5916\uff0c\u5f53bgsave\u51fa\u73b0\u9519\u8bef\u65f6\uff0cRedis\u662f\u5426\u505c\u6b62\u6267\u884c\u5199\u547d\u4ee4\u3002Redis\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53c2\u6570stop-writes-on-bgsave-error\uff0c\u8bbe\u7f6e\u4e3ayes\uff0c\u5219\u5f53\u786c\u76d8\u51fa\u73b0\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u53ca\u65f6\u53d1\u73b0\uff0c\u907f\u514d\u6570\u636e\u7684\u5927\u91cf\u4e22\u5931\uff1b\u8bbe\u7f6e\u4e3ano\uff0c\u5219Redis\u65e0\u89c6bgsave\u7684\u9519\u8bef\u7ee7\u7eed\u6267\u884c\u5199\u547d\u4ee4\uff0c\u5f53\u5bf9Redis\u670d\u52a1\u5668\u7684\u7cfb\u7edf(\u5c24\u5176\u662f\u786c\u76d8)\u4f7f\u7528\u4e86\u76d1\u63a7\u65f6\uff0c\u8be5\u9009\u9879\u8003\u8651\u8bbe\u7f6e\u4e3ano\u3002<\/p>\n

\u8bf4\u8bf4FORK\u7684\u5f00\u9500\uff1f<\/strong><\/span><\/div>\n

\u7236\u8fdb\u7a0b\u901a\u8fc7fork\u64cd\u4f5c\u53ef\u4ee5\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u7b2c\u4e00\u4ee3Unix\u7cfb\u7edf\u5b9e\u73b0\u4e86\u4e00\u79cd\u50bb\u74dc\u5f0f\u7684\u8fdb\u7a0b\u521b\u5efa\uff1a\u5f53\u6267\u884cfork\u7cfb\u7edf\u8c03\u7528\u65f6\uff0c\u5185\u6838\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u6574\u4e2a\u7528\u6237\u7a7a\u95f4\u5e76\u628a\u590d\u5236\u5f97\u5230\u7684\u90a3\u4e00\u4efd\u5206\u914d\u7ed9\u5b50\u8fdb\u7a0b\u3002\u8fd9\u79cd\u884c\u4e3a\u65f6\u975e\u5e38\u8017\u65f6\u7684\uff0c\u56e0\u4e3a\u5b83\u9700\u8981\u5b8c\u6210\u4ee5\u4e0b\u51e0\u9879\u4efb\u52a1\uff1a\u4e3a\u5b50\u8fdb\u7a0b\u7684\u9875\u8868\u5206\u914d\u9875\u9762\u3001\u4e3a\u5b50\u8fdb\u7a0b\u7684\u9875\u5206\u914d\u9875\u9762\u3001\u521d\u59cb\u5316\u5b50\u8fdb\u7a0b\u7684\u9875\u8868\u3001\u628a\u7236\u8fdb\u7a0b\u7684\u9875\u590d\u5236\u5230\u5b50\u8fdb\u7a0b\u5bf9\u5e94\u7684\u9875\u4e2d\u3002<\/p>\n

\u73b0\u5728Linux\u7684fork()\u4f7f\u7528\u5199\u65f6\u62f7\u8d1d\uff08copy-on-write\uff09\u9875\u5b9e\u73b0\u3002\u5199\u65f6\u62f7\u8d1d\u662f\u4e00\u79cd\u53ef\u4ee5\u63a8\u8fdf\u751a\u81f3\u514d\u9664\u62f7\u8d1d\u6570\u636e\u7684\u6280\u672f\u3002\u5185\u6838\u6b64\u65f6\u5e76\u4e0d\u590d\u5236\u6574\u4e2a\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\uff0c\u800c\u662f\u8ba9\u7236\u8fdb\u7a0b\u548c\u5b50\u8fdb\u7a0b\u5171\u4eab\u540c\u4e00\u4e2a\u62f7\u8d1d\u3002\u53ea\u6709\u5728\u9700\u8981\u5199\u5165\u7684\u65f6\u5019\uff0c\u6570\u636e\u624d\u4f1a\u88ab\u590d\u5236\uff0c\u4ece\u800c\u4f7f\u5404\u4e2a\u8fdb\u7a0b\u62e5\u6709\u5404\u81ea\u7684\u62f7\u8d1d\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8d44\u6e90\u7684\u590d\u5236\u53ea\u6709\u5728\u9700\u8981\u5199\u5165\u7684\u65f6\u5019\u624d\u8fdb\u884c\uff0c\u5728\u6b64\u4e4b\u524d\uff0c\u53ea\u662f\u4ee5\u53ea\u8bfb\u65b9\u5f0f\u5171\u4eab\u3002\u8fd9\u79cd\u6280\u672f\u4f7f\u5730\u5740\u7a7a\u95f4\u4e0a\u7684\u9875\u7684\u62f7\u8d1d\u88ab\u63a8\u8fdf\u5230\u5b9e\u9645\u53d1\u751f\u5199\u5165\u7684\u65f6\u5019\u3002\u6240\u4ee5\u5c31\u7b97fork\u5f88\u5927\u5185\u5b58\u7684\u8fdb\u7a0b\uff0c\u5bf9\u5185\u5b58\u7684\u6d88\u8017\u548c\u8017\u65f6\u90fd\u5f88\u5c0f\u3002<\/p>\n

\u73b0\u5728\u867d\u7136fork\u65f6\uff0c\u5b50\u8fdb\u7a0b\u4e0d\u4f1a\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u6570\u636e\u7a7a\u95f4\uff0c\u4f46\u662f\u4f1a\u590d\u5236\u5185\u5b58\u9875\u8868\uff08\u9875\u8868\u76f8\u5f53\u4e8e\u5185\u5b58\u7684\u7d22\u5f15\u3001\u76ee\u5f55\uff09\uff1b\u7236\u8fdb\u7a0b\u7684\u6570\u636e\u7a7a\u95f4\u8d8a\u5927\uff0c\u5185\u5b58\u9875\u8868\u8d8a\u5927\uff0cfork\u65f6\u590d\u5236\u8017\u65f6\u4e5f\u4f1a\u8d8a\u591a\u3002\u8fd9\u4e2a\u95ee\u9898\u4e5f\u662f\u5bfc\u81f4Redis\u5185\u5b58\u4e0d\u5b9c\u8fc7\u5927\u7684\u539f\u56e0\u4e4b\u4e00\uff0c\u5f53\u7136\u8fd8\u6709\u5bfc\u81f4\u6545\u969c\u6062\u590d\u65f6\u95f4\u5ef6\u957f\u4e5f\u662fRedis\u5185\u5b58\u4e0d\u5b9c\u8fc7\u5927\u7684\u539f\u56e0\u3002<\/p>\n

AOF\u65e5\u5fd7<\/strong><\/div>\n

\u901a\u8fc7\u4e0a\u9762\u7684\u5206\u6790\uff0c\u6211\u4eec\u77e5\u9053RDB\u5feb\u7167\u6709\u5927\u6982\u7387\u4e22\u5931\u6700\u8fd1\u5199\u5165\u3001\u4e14\u4ecd\u672a\u4fdd\u5b58\u5230\u5feb\u7167\u4e2d\u7684\u90a3\u4e9b\u6570\u636e\u3002\u5c3d\u7ba1\u5bf9\u4e8e\u67d0\u4e9b\u7a0b\u5e8f\u6765\u8bf4\uff0c\u6570\u636e\u5b89\u5168\u5e76\u4e0d\u662f\u6700\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\uff0c\u4f46\u662f\u5bf9\u4e8e\u90a3\u4e9b\u8ffd\u6c42\u6570\u636e\u5b89\u5168\u7684\u7a0b\u5e8f\u6765\u8bf4\uff0c\u5feb\u7167\u529f\u80fd\u5c31\u4e0d\u592a\u9002\u7528\u4e86\u3002\u4ece1.1\u7248\u672c\u5f00\u59cb\uff0cRedis\u589e\u52a0\u4e86\u4e00\u79cd\u5b9e\u65f6\u6027\u66f4\u597d\u7684\u6301\u4e45\u5316\u65b9\u5f0f\uff0c\u5373AOF\u6301\u4e45\u5316\u3002AOF\u65e5\u5fd7\u7684\u5168\u79f0\u662fappend only file\uff0c\u4ece\u540d\u5b57\u4e0a\u6211\u4eec\u5c31\u80fd\u770b\u51fa\u6765\uff0c\u5b83\u662f\u4e00\u4e2a\u8ffd\u52a0\u5199\u5165\u7684\u65e5\u5fd7\u6587\u4ef6\u3002\u4e0eRDB\u76f8\u6bd4\uff0cAOF\u7684\u5b9e\u65f6\u6027\u66f4\u597d\uff0c\u56e0\u6b64\u5df2\u6210\u4e3a\u4e3b\u6d41\u7684\u6301\u4e45\u5316\u65b9\u6848\u3002<\/p>\n

AOF\u6587\u4ef6\u4e0eMySQL\u6570\u636e\u5e93\u7684binlog\u4e0d\u540c\u7684\u662f\uff0cAOF\u662f\u4e00\u79cd\u7eaf\u6587\u672c\u683c\u5f0f\uff0c\u5177\u6709\u517c\u5bb9\u6027\u597d\u3001\u53ef\u8bfb\u6027\u5f3a\u3001\u5bb9\u6613\u5904\u7406\u3001\u64cd\u4f5c\u7b80\u5355\u907f\u514d\u4e8c\u6b21\u5f00\u9500\u7b49\u4f18\u70b9\uff0c\u5b83\u8bb0\u5f55\u7684\u5185\u5bb9\u5c31\u662f\u4e00\u4e2a\u4e2a\u7684Redis\u6807\u51c6\u547d\u4ee4\u3002\u5f00\u542fAOF\u6301\u4e45\u5316\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n

\r\nappendonly yes\r\nappendfilename \"appendonly.aof\"\r\n<\/pre>\n

\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6bcf\u5f53Redis\u6267\u884c\u4e00\u4e2a\u6539\u53d8\u6570\u636e\u96c6\u7684\u547d\u4ee4\u65f6\uff08\u6bd4\u5982SET\uff09\uff0c\u8fd9\u4e2a\u547d\u4ee4\u5c31\u4f1a\u88ab\u8ffd\u52a0\u5230AOF\u6587\u4ef6\u7684\u672b\u5c3e\u3002\u8fd9\u6837\u7684\u8bdd\uff0c\u5f53Redis\u91cd\u65b0\u542f\u65f6\uff0c\u7a0b\u5e8f\u5c31\u53ef\u4ee5\u901a\u8fc7\u91cd\u65b0\u6267\u884cAOF\u6587\u4ef6\u4e2d\u7684\u547d\u4ee4\u6765\u8fbe\u5230\u91cd\u5efa\u6570\u636e\u96c6\u7684\u76ee\u7684\u3002<\/p>\n

\u7531\u4e8e\u9700\u8981\u8bb0\u5f55Redis\u7684\u6bcf\u6761\u5199\u547d\u4ee4\uff0c\u56e0\u6b64AOF\u4e0d\u9700\u8981\u89e6\u53d1\uff0c\u4e0b\u9762\u4ecb\u7ecdAOF\u7684\u6267\u884c\u6d41\u7a0b\uff1a<\/p>\n

\u547d\u4ee4\u8ffd\u52a0\uff08append\uff09<\/strong><\/span><\/div>\n

Redis\u5148\u5c06\u5199\u547d\u4ee4\u8ffd\u52a0\u5230\u7f13\u51b2\u533a\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u5199\u5165\u6587\u4ef6\uff0c\u4e3b\u8981\u662f\u4e3a\u4e86\u907f\u514d\u6bcf\u6b21\u6709\u5199\u547d\u4ee4\u90fd\u76f4\u63a5\u5199\u5165\u786c\u76d8\uff0c\u5bfc\u81f4\u786c\u76d8IO\u6210\u4e3aRedis\u8d1f\u8f7d\u7684\u74f6\u9888\u3002<\/p>\n

\u6587\u4ef6\u5199\u5165\uff08write\uff09\u548c\u6587\u4ef6\u540c\u6b65\uff08sync\uff09<\/strong><\/span><\/div>\n

Redis\u63d0\u4f9b\u4e86\u591a\u79cdAOF\u7f13\u5b58\u533a\u7684\u540c\u6b65\u6587\u4ef6\u7b56\u7565\uff0c\u7b56\u7565\u6d89\u53ca\u5230\u64cd\u4f5c\u7cfb\u7edf\u7684write\u51fd\u6570\u548cfsync\u51fd\u6570\uff0c\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n

\u4e3a\u4e86\u63d0\u9ad8\u6587\u4ef6\u5199\u5165\u6548\u7387\uff0c\u5728\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u5f53\u7528\u6237\u8c03\u7528write\u51fd\u6570\u5c06\u6570\u636e\u5199\u5165\u6587\u4ef6\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u901a\u5e38\u4f1a\u5c06\u6570\u636e\u6682\u5b58\u5230\u4e00\u4e2a\u5185\u5b58\u7f13\u51b2\u533a\u91cc\uff0c\u5f53\u7f13\u51b2\u533a\u88ab\u586b\u6ee1\u6216\u8d85\u8fc7\u4e86\u6307\u5b9a\u65f6\u9650\u540e\uff0c\u624d\u771f\u6b63\u5c06\u7f13\u51b2\u533a\u7684\u6570\u636e\u5199\u5165\u5230\u786c\u76d8\u91cc\u3002\u8fd9\u6837\u7684\u64cd\u4f5c\u867d\u7136\u63d0\u9ad8\u4e86\u6548\u7387\uff0c\u4f46\u4e5f\u5e26\u6765\u4e86\u5b89\u5168\u95ee\u9898\uff1a\u5982\u679c\u8ba1\u7b97\u673a\u505c\u673a\uff0c\u5185\u5b58\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u4f1a\u4e22\u5931\uff1b\u56e0\u6b64\u7cfb\u7edf\u540c\u65f6\u63d0\u4f9b\u4e86fsync\u3001fdatasync\u7b49\u540c\u6b65\u51fd\u6570\uff0c\u53ef\u4ee5\u5f3a\u5236\u64cd\u4f5c\u7cfb\u7edf\u7acb\u523b\u5c06\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u5199\u5165\u5230\u786c\u76d8\u91cc\uff0c\u4ece\u800c\u786e\u4fdd\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n

AOF\u7f13\u5b58\u533a\u7684\u540c\u6b65\u6587\u4ef6\u7b56\u7565\u7531\u53c2\u6570appendfsync\u63a7\u5236\uff0c\u5404\u4e2a\u503c\u7684\u542b\u4e49\u5982\u4e0b\uff1a<\/p>\n

always\uff1a\u547d\u4ee4\u5199\u5165aof_buf\u540e\u7acb\u5373\u8c03\u7528\u7cfb\u7edffsync\u64cd\u4f5c\u540c\u6b65\u5230AOF\u6587\u4ef6\uff0cfsync\u5b8c\u6210\u540e\u7ebf\u7a0b\u8fd4\u56de\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u6709\u5199\u547d\u4ee4\u90fd\u8981\u540c\u6b65\u5230AOF\u6587\u4ef6\uff0c\u786c\u76d8IO\u6210\u4e3a\u6027\u80fd\u74f6\u9888\uff0cRedis\u53ea\u80fd\u652f\u6301\u5927\u7ea6\u51e0\u767eTPS\u5199\u5165\uff0c\u4e25\u91cd\u964d\u4f4e\u4e86Redis\u7684\u6027\u80fd\uff1b\u5373\u4fbf\u662f\u4f7f\u7528\u56fa\u6001\u786c\u76d8\uff08SSD\uff09\uff0c\u6bcf\u79d2\u5927\u7ea6\u4e5f\u53ea\u80fd\u5904\u7406\u51e0\u4e07\u4e2a\u547d\u4ee4\uff0c\u800c\u4e14\u4f1a\u5927\u5927\u964d\u4f4eSSD\u7684\u5bff\u547d\u3002<\/p>\n

no\uff1a\u547d\u4ee4\u5199\u5165aof_buf\u540e\u8c03\u7528\u7cfb\u7edfwrite\u64cd\u4f5c\uff0c\u4e0d\u5bf9AOF\u6587\u4ef6\u505afsync\u540c\u6b65\uff1b\u540c\u6b65\u7531\u64cd\u4f5c\u7cfb\u7edf\u8d1f\u8d23\uff0c\u901a\u5e38\u540c\u6b65\u5468\u671f\u4e3a30\u79d2\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6587\u4ef6\u540c\u6b65\u7684\u65f6\u95f4\u4e0d\u53ef\u63a7\uff0c\u4e14\u7f13\u51b2\u533a\u4e2d\u5806\u79ef\u7684\u6570\u636e\u4f1a\u5f88\u591a\uff0c\u6570\u636e\u5b89\u5168\u6027\u65e0\u6cd5\u4fdd\u8bc1\u3002
\neverysec\uff1a\u547d\u4ee4\u5199\u5165aof_buf\u540e\u8c03\u7528\u7cfb\u7edfwrite\u64cd\u4f5c\uff0cwrite\u5b8c\u6210\u540e\u7ebf\u7a0b\u8fd4\u56de\uff1bfsync\u540c\u6b65\u6587\u4ef6\u64cd\u4f5c\u7531\u4e13\u95e8\u7684\u7ebf\u7a0b\u6bcf\u79d2\u8c03\u7528\u4e00\u6b21\u3002everysec\u662f\u524d\u8ff0\u4e24\u79cd\u7b56\u7565\u7684\u6298\u4e2d\uff0c\u662f\u6027\u80fd\u548c\u6570\u636e\u5b89\u5168\u6027\u7684\u5e73\u8861\uff0c\u56e0\u6b64\u662fRedis\u7684\u9ed8\u8ba4\u914d\u7f6e\uff0c\u4e5f\u662f\u6211\u4eec\u63a8\u8350\u7684\u914d\u7f6e\u3002<\/p>\n

\u6587\u4ef6\u91cd\u5199\uff08rewrite\uff09<\/strong><\/span><\/div>\n

\u56e0\u4e3aAOF\u7684\u8fd0\u4f5c\u65b9\u5f0f\u662f\u4e0d\u65ad\u5730\u5c06\u547d\u4ee4\u8ffd\u52a0\u5230\u6587\u4ef6\u7684\u672b\u5c3e\uff0c\u6240\u4ee5\u968f\u7740\u5199\u5165\u547d\u4ee4\u7684\u4e0d\u65ad\u589e\u52a0\uff0cAOF\u6587\u4ef6\u7684\u4f53\u79ef\u4e5f\u4f1a\u53d8\u5f97\u8d8a\u6765\u8d8a\u5927\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u4f60\u5bf9\u4e00\u4e2a\u8ba1\u6570\u5668\u8c03\u7528\u4e86100\u6b21INCR\uff0c\u90a3\u4e48\u4ec5\u4ec5\u662f\u4e3a\u4e86\u4fdd\u5b58\u8fd9\u4e2a\u8ba1\u6570\u5668\u7684\u5f53\u524d\u503c\uff0cAOF\u6587\u4ef6\u5c31\u9700\u8981\u4f7f\u7528100\u6761\u8bb0\u5f55\uff08entry\uff09\u3002\u7136\u800c\u5728\u5b9e\u9645\u4e0a\uff0c\u53ea\u4f7f\u7528\u4e00\u6761SET\u547d\u4ee4\u5df2\u7ecf\u8db3\u4ee5\u4fdd\u5b58\u8ba1\u6570\u5668\u7684\u5f53\u524d\u503c\u4e86\uff0c\u5176\u4f5999\u6761\u8bb0\u5f55\u5b9e\u9645\u4e0a\u90fd\u662f\u591a\u4f59\u7684\u3002\u53e6\u5916\u8fd8\u6709\u4e00\u4e9b\u8fc7\u671f\u7684\u6570\u636e\uff0c\u65e0\u6548\u7684\u6570\u636e\u4e5f\u90fd\u662f\u53ef\u4ee5\u53bb\u9664\u3002<\/p>\n

\u8fc7\u5927\u7684AOF\u6587\u4ef6\u4e0d\u4ec5\u4f1a\u5f71\u54cd\u670d\u52a1\u5668\u7684\u6b63\u5e38\u8fd0\u884c\uff0c\u4e5f\u4f1a\u5bfc\u81f4\u6570\u636e\u6062\u590d\u9700\u8981\u7684\u65f6\u95f4\u8fc7\u957f\u3002\u4e3a\u4e86\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\uff0cRedis\u652f\u6301\u4e00\u79cd\u6709\u8da3\u7684\u7279\u6027\uff0c\u53ef\u4ee5\u5728\u4e0d\u6253\u65ad\u670d\u52a1\u5ba2\u6237\u7aef\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9AOF\u6587\u4ef6\u8fdb\u884c\u91cd\u5efa\uff08rebuild\uff09\u3002\u6267\u884cBGREWRITEAOF\u547d\u4ee4\uff0c Redis\u5c06\u751f\u6210\u4e00\u4e2a\u65b0\u7684AOF\u6587\u4ef6\uff0c \u8fd9\u4e2a\u6587\u4ef6\u5305\u542b\u91cd\u5efa\u5f53\u524d\u6570\u636e\u96c6\u6240\u9700\u7684\u6700\u5c11\u547d\u4ee4\u3002<\/p>\n

AOF REWRITE\uff08\u91cd\u5199\uff09\u751f\u6210\u8fc7\u7a0b\u548cRDB\u5feb\u7167\u7c7b\u4f3c\uff0c\u90fd\u5de7\u5999\u5730\u5229\u7528\u4e86\u5199\u65f6\u590d\u5236\u673a\u5236\u3002\u540c\u6837\u4e5f\u662ffork\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff08\u6b64\u65f6\u4e3b\u7ebf\u7a0b\u662f\u963b\u585e\u7684\uff09\uff0c\u5b50\u8fdb\u7a0b\u6839\u636e\u5185\u5b58\u5feb\u7167\uff0c\u6309\u7167\u547d\u4ee4\u5408\u5e76\u89c4\u5219\u5199\u5165\u5230\u65b0\u7684AOF\u6587\u4ef6\u3002\u5f53\u4e3b\u8fdb\u7a0bfork\u5b8c\u5b50\u7ebf\u7a0b\u540e\u7ee7\u7eed\u63a5\u53d7\u8bf7\u6c42\uff0c\u6240\u6709\u5199\u547d\u4ee4\u4f9d\u7136\u5199\u5165AOF\u7f13\u51b2\u533a\uff08aof_buf\uff09\uff0c\u5e76\u6839\u636eappendfsync\u7b56\u7565\u540c\u6b65\u5230\u786c\u76d8\uff0c\u4fdd\u8bc1\u539f\u6709AOF\u673a\u5236\u7684\u6b63\u786e\u3002\u4f46\u7531\u4e8efork\u64cd\u4f5c\u4f7f\u7528\u5199\u65f6\u590d\u5236\u6280\u672f\uff0c\u5b50\u8fdb\u7a0b\u53ea\u80fd\u5171\u4eabfork\u64cd\u4f5c\u65f6\u7684\u5185\u5b58\u6570\u636e\u3002\u7531\u4e8e\u7236\u8fdb\u7a0b\u4f9d\u7136\u5728\u54cd\u5e94\u547d\u4ee4\uff0c\u56e0\u6b64Redis\u4f7f\u7528AOF\u91cd\u5199\u7f13\u51b2\u533a\uff08aof_rewrite_buf\uff09\u4fdd\u5b58\u8fd9\u90e8\u5206\u65b0\u65e5\u5fd7\uff0c\u9632\u6b62\u65b0AOF\u6587\u4ef6\u751f\u6210\u671f\u95f4\u4e22\u5931\u8fd9\u90e8\u5206\u6570\u636e\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cbgrewriteaof\u6267\u884c\u671f\u95f4\uff0cRedis\u7684\u5199\u547d\u4ee4\u540c\u65f6\u8ffd\u52a0\u5230aof_buf\u548caof_rewirte_buf\u4e24\u4e2a\u7f13\u51b2\u533a\u3002<\/p>\n

\u5f53\u5b50\u8fdb\u7a0b\u5199\u5b8c\u65b0\u7684AOF\u6587\u4ef6\u540e\uff0c\u5411\u7236\u8fdb\u7a0b\u53d1\u4fe1\u53f7\uff0c\u7236\u8fdb\u7a0b\u66f4\u65b0\u7edf\u8ba1\u4fe1\u606f\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7info persistence\u67e5\u770b\u3002\u7136\u540e\u7236\u8fdb\u7a0b\u628aAOF\u91cd\u5199\u7f13\u51b2\u533a\u7684\u6570\u636e\u5199\u5165\u5230\u65b0\u7684AOF\u6587\u4ef6\uff0c\u8fd9\u6837\u5c31\u4fdd\u8bc1\u4e86\u65b0AOF\u6587\u4ef6\u6240\u4fdd\u5b58\u7684\u6570\u636e\u5e93\u72b6\u6001\u548c\u670d\u52a1\u5668\u5f53\u524d\u72b6\u6001\u4e00\u81f4\u3002\u7136\u540e\u8c03\u7528\u539f\u5b50\u6027\u7684rename\u547d\u4ee4\u7528\u65b0\u7684AOF\u6587\u4ef6\u53d6\u4ee3\u8001\u7684AOF\u6587\u4ef6\uff0c\u5b8c\u6210AOF\u91cd\u5199\u3002<\/p>\n

\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff0c\u56e0\u4e3a\u7531\u4e3b\u8fdb\u7a0b\u628aaof_rewrite_buf\u7f13\u5b58\u8ffd\u52a0\u5230\u65b0\u65e5\u5fd7\u6587\u4ef6\u3002\u4e3b\u8fdb\u7a0b\u8ffd\u52a0\u65e5\u5fd7\u65f6\uff0c\u4e0d\u4f1a\u5904\u7406\u5176\u4ed6\u8bf7\u6c42\uff0c\u5982\u679caof_rewrite_buf\u7279\u522b\u5927\uff0c\u4f8b\u5982\u51e0\u767eM\uff0c\u4e5f\u53ef\u80fd\u9020\u6210Redis\u51e0\u79d2\u751a\u81f3\u51e0\u5341\u79d2\u4e0d\u54cd\u5e94\u3002<\/p>\n

\u4ece\u4e0a\u9762\u7684\u6d41\u7a0b\u6211\u4eec\u80fd\u591f\u770b\u5230\uff0cRDB\u548cAOF\u64cd\u4f5c\u90fd\u662f\u987a\u5e8fIO\u64cd\u4f5c\uff0c\u6027\u80fd\u90fd\u5f88\u9ad8\u3002\u800c\u5728\u901a\u8fc7RDB\u6587\u4ef6\u6216\u8005AOF\u65e5\u5fd7\u8fdb\u884c\u6570\u636e\u5e93\u6062\u590d\u7684\u65f6\u5019\uff0c\u4e5f\u662f\u987a\u5e8f\u7684\u8bfb\u53d6\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u6240\u4ee5\u4e5f\u4e0d\u4f1a\u9020\u6210\u78c1\u76d8\u7684\u968f\u673a\u8bfb\u3002<\/p>\n

\u6587\u4ef6\u91cd\u5199\u7684\u89e6\u53d1\uff0c\u5206\u4e3a\u624b\u52a8\u89e6\u53d1\u548c\u81ea\u52a8\u89e6\u53d1\uff1a<\/p>\n

\u624b\u52a8\u89e6\u53d1\uff1a\u76f4\u63a5\u8c03\u7528bgrewriteaof\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u7684\u6267\u884c\u4e0ebgsave\u6709\u4e9b\u7c7b\u4f3c\uff1a\u90fd\u662ffork\u5b50\u8fdb\u7a0b\u8fdb\u884c\u5177\u4f53\u7684\u5de5\u4f5c\uff0c\u4e14\u90fd\u53ea\u6709\u5728fork\u65f6\u963b\u585e\u3002<\/p>\n

\u81ea\u52a8\u89e6\u53d1\uff1a\u6839\u636eauto-aof-rewrite-min-size\u548cauto-aof-rewrite-percentage\u53c2\u6570\uff0c\u4ee5\u53caaof_current_size\u548caof_base_size\u72b6\u6001\u786e\u5b9a\u89e6\u53d1\u65f6\u673a\u3002<\/p>\n

auto-aof-rewrite-min-size\u8868\u793a\u6267\u884cAOF\u91cd\u5199\u65f6\uff0c\u6587\u4ef6\u7684\u6700\u5c0f\u4f53\u79ef\uff0c\u9ed8\u8ba4\u503c\u4e3a64MB\u3002<\/p>\n

auto-aof-rewrite-percentage\u8868\u793a\u6267\u884cAOF\u91cd\u5199\u65f6\uff0c\u5f53\u524dAOF\u5927\u5c0f\uff08\u5373aof_current_size\uff09\u548c\u4e0a\u4e00\u6b21\u91cd\u5199\u65f6AOF\u5927\u5c0f\uff08aof_base_size\uff09\u7684\u6bd4\u503c\uff0c\u5373\u589e\u957f\u6bd4\u4f8b\u8fbe\u5230\u8bbe\u5b9a\u503c\u3002<\/p>\n

\u53ea\u6709\u5f53auto-aof-rewrite-min-size\u548cauto-aof-rewrite-percentage\u4e24\u4e2a\u53c2\u6570\u540c\u65f6\u6ee1\u8db3\u65f6\uff0c\u624d\u4f1a\u81ea\u52a8\u89e6\u53d1AOF\u91cd\u5199\uff0c\u5373bgrewriteaof\u64cd\u4f5c\u3002<\/p>\n

\u5176\u4e2d\uff0c\u53c2\u6570\u53ef\u4ee5\u901a\u8fc7config get\u547d\u4ee4\u67e5\u770b\uff1a<\/p>\n

\r\n127.0.0.1:6391> CONFIG GET auto-aof-rewrite-min-size\r\n1) \"auto-aof-rewrite-min-size\"\r\n2) \"64000000\"\r\n127.0.0.1:6391> CONFIG GET auto-aof-rewrite-percentage\r\n1) \"auto-aof-rewrite-percentage\"\r\n2) \"100\"\r\n<\/pre>\n

\u72b6\u6001\u53ef\u4ee5\u901a\u8fc7info persistence\u67e5\u770b\uff1a<\/p>\n

\r\n127.0.0.1:6379> info persistence\r\n# Persistence\r\naof_enabled:1\r\naof_rewrite_in_progress:0\r\naof_rewrite_scheduled:0\r\naof_last_rewrite_time_sec:0\r\naof_current_rewrite_time_sec:-1\r\naof_last_bgrewrite_status:ok\r\naof_last_write_status:ok\r\naof_current_size:40876638\r\naof_base_size:2217565\r\naof_pending_rewrite:0\r\naof_buffer_length:0\r\naof_rewrite_buffer_length:0\r\naof_pending_bio_fsync:0\r\naof_delayed_fsync:0\r\n<\/pre>\n

\u53e6\u5916\u5728aof rewrite\u8fc7\u7a0b\u4e2d\uff0c\u662f\u5426\u91c7\u53d6\u589e\u91cf\u201d\u6587\u4ef6\u540c\u6b65\u201d\u7b56\u7565\uff0c\u7531\u53c2\u6570aof-rewrite-incremental-fsync\u63a7\u5236\uff0c\u9ed8\u8ba4\u4e3a\u201dyes\u201d\uff0c\u800c\u4e14\u5fc5\u987b\u4e3ayes\u3002rewrite\u8fc7\u7a0b\u4e2d\uff0c\u6bcf32M\u6570\u636e\u8fdb\u884c\u4e00\u6b21\u6587\u4ef6\u540c\u6b65\uff0c\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u201daof\u5927\u6587\u4ef6\u201d\u5199\u5165\u5bf9\u78c1\u76d8\u7684\u64cd\u4f5c\u6b21\u6570\u3002<\/p>\n

bgrewriteaof\u673a\u5236\uff0c\u5728\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u4e2d\u8fdb\u884caof\u7684\u91cd\u5199\uff0c\u4ece\u800c\u4e0d\u963b\u585e\u4e3b\u8fdb\u7a0b\u5bf9\u5176\u4f59\u547d\u4ee4\u7684\u5904\u7406\uff0c\u540c\u65f6\u89e3\u51b3\u4e86aof\u6587\u4ef6\u8fc7\u5927\u95ee\u9898\u3002\u73b0\u5728\u95ee\u9898\u51fa\u73b0\u4e86\uff0c\u540c\u65f6\u5728\u6267\u884cbgrewriteaof\u64cd\u4f5c\u548c\u4e3b\u8fdb\u7a0b\u5199aof\u6587\u4ef6\u7684\u64cd\u4f5c\uff0c\u4e24\u8005\u90fd\u4f1a\u64cd\u4f5c\u78c1\u76d8\uff0c\u800cbgrewriteaof\u5f80\u5f80\u4f1a\u6d89\u53ca\u5927\u91cf\u78c1\u76d8\u64cd\u4f5c\uff0c\u8fd9\u6837\u5c31\u4f1a\u9020\u6210\u4e3b\u8fdb\u7a0b\u5728\u5199aof\u6587\u4ef6\u7684\u65f6\u5019\u51fa\u73b0\u963b\u585e\u7684\u60c5\u5f62\uff0c\u73b0\u5728no-appendfsync-on-rewrite\u53c2\u6570\u51fa\u573a\u4e86\u3002<\/p>\n

\u5982\u679c\u8be5\u53c2\u6570\u8bbe\u7f6e\u4e3ano\uff0c\u662f\u6700\u5b89\u5168\u7684\u65b9\u5f0f\uff0c\u4e0d\u4f1a\u4e22\u5931\u6570\u636e\uff0c\u4f46\u662f\u8981\u5fcd\u53d7\u963b\u585e\u7684\u95ee\u9898\u3002\u5982\u679c\u8bbe\u7f6e\u4e3ayes\u5462\uff1f\u8fd9\u5c31\u76f8\u5f53\u4e8e\u5c06appendfsync\u8bbe\u7f6e\u4e3ano\uff0c\u8fd9\u8bf4\u660e\u5e76\u6ca1\u6709\u6267\u884c\u78c1\u76d8\u64cd\u4f5c\uff0c\u53ea\u662f\u5199\u5165\u4e86\u7f13\u51b2\u533a\uff0c\u56e0\u6b64\u8fd9\u6837\u5e76\u4e0d\u4f1a\u9020\u6210\u963b\u585e\uff08\u56e0\u4e3a\u6ca1\u6709\u7ade\u4e89\u78c1\u76d8\uff09\uff0c\u4f46\u662f\u5982\u679c\u8fd9\u4e2a\u65f6\u5019Redis\u6302\u6389\uff0c\u5c31\u4f1a\u4e22\u5931\u6570\u636e\u3002\u4e22\u5931\u591a\u5c11\u6570\u636e\u5462\uff1f\u5728Linux\u7684\u64cd\u4f5c\u7cfb\u7edf\u7684\u9ed8\u8ba4\u8bbe\u7f6e\u4e0b\uff0c\u6700\u591a\u4f1a\u4e22\u593130s\u7684\u6570\u636e\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5e94\u7528\u7cfb\u7edf\u65e0\u6cd5\u5fcd\u53d7\u5ef6\u8fdf\uff0c\u800c\u53ef\u4ee5\u5bb9\u5fcd\u5c11\u91cf\u7684\u6570\u636e\u4e22\u5931\uff0c\u5219\u8bbe\u7f6e\u4e3ayes\u3002\u5982\u679c\u5e94\u7528\u7cfb\u7edf\u65e0\u6cd5\u5fcd\u53d7\u6570\u636e\u4e22\u5931\uff0c\u5219\u8bbe\u7f6e\u4e3ano\u3002<\/p>\n

AOF\u5237\u65b0\u7b56\u7565\uff1f<\/strong><\/span><\/div>\n

\u524d\u9762\u63d0\u5230\u8fc7\uff0c\u5728AOF\u4e2d\uff0c\u5982\u679cAOF\u7f13\u51b2\u533a\u7684\u6587\u4ef6\u540c\u6b65\u7b56\u7565\u4e3aeverysec\uff0c\u5219\uff1a\u5728\u4e3b\u7ebf\u7a0b\u4e2d\uff0c\u547d\u4ee4\u5199\u5165aof_buf\u540e\u8c03\u7528\u7cfb\u7edfwrite\u64cd\u4f5c\uff0cwrite\u5b8c\u6210\u540e\u4e3b\u7ebf\u7a0b\u8fd4\u56de\uff1bfsync\u540c\u6b65\u6587\u4ef6\u64cd\u4f5c\u7531\u4e13\u95e8\u7684\u6587\u4ef6\u540c\u6b65\u7ebf\u7a0b\u6bcf\u79d2\u8c03\u7528\u4e00\u6b21\u3002\u8fd9\u79cd\u505a\u6cd5\u7684\u95ee\u9898\u5728\u4e8e\uff0c\u5982\u679c\u786c\u76d8\u8d1f\u8f7d\u8fc7\u9ad8\uff0c\u90a3\u4e48fsync\u64cd\u4f5c\u53ef\u80fd\u4f1a\u8d85\u8fc71s\uff1b\u5982\u679cRedis\u4e3b\u7ebf\u7a0b\u6301\u7eed\u9ad8\u901f\u5411aof_buf\u5199\u5165\u547d\u4ee4\uff0c\u786c\u76d8\u7684\u8d1f\u8f7d\u53ef\u80fd\u4f1a\u8d8a\u6765\u8d8a\u5927\uff0cIO\u8d44\u6e90\u6d88\u8017\u66f4\u5feb\uff1b\u5982\u679c\u6b64\u65f6Redis\u8fdb\u7a0b\u5f02\u5e38\u9000\u51fa\uff0c\u4e22\u5931\u7684\u6570\u636e\u4e5f\u4f1a\u8d8a\u6765\u8d8a\u591a\uff0c\u53ef\u80fd\u8fdc\u8d85\u8fc71s\u3002<\/p>\n

\u4e3a\u6b64\uff0cRedis\u7684\u5904\u7406\u7b56\u7565\u662f\u8fd9\u6837\u7684\uff1a\u4e3b\u7ebf\u7a0b\u6bcf\u6b21\u8fdb\u884cAOF\u4f1a\u5bf9\u6bd4\u4e0a\u6b21fsync\u6210\u529f\u7684\u65f6\u95f4\uff1b\u5982\u679c\u8ddd\u4e0a\u6b21\u4e0d\u52302s\uff08\u4e5f\u5c31\u662f\u5ef6\u8fdf\u4e861s\uff09\uff0c\u4e3b\u7ebf\u7a0b\u76f4\u63a5\u8fd4\u56de\uff1b\u5982\u679c\u8d85\u8fc72s\uff0c\u5219\u4e3b\u7ebf\u7a0b\u963b\u585e\u76f4\u5230\u4e0a\u4e00\u6b21fsync\u540c\u6b65\u5b8c\u6210\u3002\u56e0\u6b64\uff0c\u5982\u679c\u7cfb\u7edf\u786c\u76d8\u8d1f\u8f7d\u8fc7\u5927\u5bfc\u81f4fsync\u901f\u5ea6\u592a\u6162\uff0c\u4f1a\u5bfc\u81f4Redis\u4e3b\u7ebf\u7a0b\u7684\u963b\u585e\uff1b\u6b64\u5916\uff0c\u4f7f\u7528everysec\u914d\u7f6e\uff0cAOF\u6700\u591a\u53ef\u80fd\u4e22\u59312s\u7684\u6570\u636e\uff0c\u800c\u4e0d\u662f1s\u3002\u5177\u4f53\u770bRedis AOF\u5237\u65b0\u7b56\u7565\u5206\u6790<\/p>\n

AOF\u8ffd\u52a0\u963b\u585e\u95ee\u9898\u5b9a\u4f4d\u7684\u65b9\u6cd5\uff0c\u76d1\u63a7info Persistence\u4e2d\u7684aof_delayed_fsync\uff0c\u5f53AOF\u8ffd\u52a0\u963b\u585e\u53d1\u751f\u65f6\uff08\u5373\u4e3b\u7ebf\u7a0b\u7b49\u5f85fsync\u800c\u963b\u585e\uff09\uff0c\u8be5\u6307\u6807\u7d2f\u52a0\u3002\u53e6\u5916\uff0cAOF\u963b\u585e\u65f6\u7684Redis\u65e5\u5fd7\uff1aAsynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for fsync to complete, this may slow down Redis.<\/p>\n

\u5982\u679cAOF\u8ffd\u52a0\u963b\u585e\u9891\u7e41\u53d1\u751f\uff0c\u8bf4\u660e\u7cfb\u7edf\u7684\u786c\u76d8\u8d1f\u8f7d\u592a\u5927\uff1b\u53ef\u4ee5\u8003\u8651\u66f4\u6362IO\u901f\u5ea6\u66f4\u5feb\u7684\u786c\u76d8\uff0c\u6216\u8005\u901a\u8fc7IO\u76d1\u63a7\u5206\u6790\u5de5\u5177\u5bf9\u7cfb\u7edf\u7684IO\u8d1f\u8f7d\u8fdb\u884c\u5206\u6790\u3002<\/p>\n

\u5bf9\u4e8epipelining\u6709\u4ec0\u4e48\u4e0d\u540c\uff1f<\/strong><\/span><\/div>\n

\u5bf9\u4e8epipelining\u7684\u64cd\u4f5c\uff0c\u5176\u5177\u4f53\u8fc7\u7a0b\u662f\u5ba2\u6237\u7aef\u4e00\u6b21\u6027\u53d1\u9001N\u4e2a\u547d\u4ee4\uff0c\u7136\u540e\u7b49\u5f85\u8fd9N\u4e2a\u547d\u4ee4\u7684\u8fd4\u56de\u7ed3\u679c\u88ab\u4e00\u8d77\u8fd4\u56de\u3002\u901a\u8fc7\u91c7\u7528pipilining\u5c31\u610f\u5473\u7740\u653e\u5f03\u4e86\u5bf9\u6bcf\u4e00\u4e2a\u547d\u4ee4\u7684\u8fd4\u56de\u503c\u786e\u8ba4\u3002\u7531\u4e8e\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cN\u4e2a\u547d\u4ee4\u662f\u5728\u540c\u4e00\u4e2a\u6267\u884c\u8fc7\u7a0b\u4e2d\u6267\u884c\u7684\u3002\u6240\u4ee5\u5f53\u8bbe\u7f6eappendfsync\u4e3aeverysec\u65f6\uff0c\u53ef\u80fd\u4f1a\u6709\u4e00\u4e9b\u504f\u5dee\uff0c\u56e0\u4e3a\u8fd9N\u4e2a\u547d\u4ee4\u53ef\u80fd\u6267\u884c\u65f6\u95f4\u8d85\u8fc71\u79d2\u751a\u81f32\u79d2\u3002\u4f46\u662f\u53ef\u4ee5\u4fdd\u8bc1\u7684\u662f\uff0c\u6700\u957f\u65f6\u95f4\u4e0d\u4f1a\u8d85\u8fc7\u8fd9N\u4e2a\u547d\u4ee4\u7684\u6267\u884c\u65f6\u95f4\u548c\u3002<\/p>\n

\u5982\u679cAOF\u6587\u4ef6\u51fa\u9519\u4e86\uff0c\u600e\u4e48\u529e\uff1f<\/strong><\/span><\/div>\n

\u670d\u52a1\u5668\u53ef\u80fd\u5728\u7a0b\u5e8f\u6b63\u5728\u5bf9AOF\u6587\u4ef6\u8fdb\u884c\u5199\u5165\u65f6\u505c\u673a\uff0c\u5982\u679c\u505c\u673a\u9020\u6210\u4e86 AOF \u6587\u4ef6\u51fa\u9519\uff08corrupt\uff09\uff0c\u90a3\u4e48Redis\u5728\u91cd\u542f\u65f6\u4f1a\u62d2\u7edd\u8f7d\u5165\u8fd9\u4e2aAOF\u6587\u4ef6\uff0c \u4ece\u800c\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u4e0d\u4f1a\u88ab\u7834\u574f\u3002\u5f53\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u65f6\uff0c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6765\u4fee\u590d\u51fa\u9519\u7684 AOF \u6587\u4ef6\uff1a\u4e3a\u73b0\u6709\u7684AOF\u6587\u4ef6\u521b\u5efa\u4e00\u4e2a\u5907\u4efd\u3002\u7136\u540e\u4f7f\u7528Redis\u9644\u5e26\u7684redis-check-aof --fix\u7a0b\u5e8f\u5bf9\u539f\u6765\u7684AOF\u6587\u4ef6\u8fdb\u884c\u4fee\u590d\u3002<\/p>\n

\u7136\u540e\u53ef\u9009\u4f7f\u7528 diff -u \u5bf9\u6bd4\u4fee\u590d\u540e\u7684 AOF \u6587\u4ef6\u548c\u539f\u59cb AOF \u6587\u4ef6\u7684\u5907\u4efd\uff0c\u67e5\u770b\u4e24\u4e2a\u6587\u4ef6\u4e4b\u95f4\u7684\u4e0d\u540c\u4e4b\u5904\u3002\u518d\u6b21\u91cd\u542fRedis\u670d\u52a1\u5668\uff0c\u7b49\u5f85\u670d\u52a1\u5668\u8f7d\u5165\u4fee\u590d\u540e\u7684AOF\u6587\u4ef6\uff0c\u5e76\u8fdb\u884c\u6570\u636e\u6062\u590d\u3002<\/p>\n

\u4f46\u5982\u679c\u662fAOF\u6587\u4ef6\u7ed3\u5c3e\u4e0d\u5b8c\u6574\uff08\u673a\u5668\u7a81\u7136\u5b95\u673a\u7b49\u5bb9\u6613\u5bfc\u81f4\u6587\u4ef6\u5c3e\u90e8\u4e0d\u5b8c\u6574\uff09\uff0c\u4e14aof-load-truncated\u53c2\u6570\u5f00\u542f\uff0c\u5219\u65e5\u5fd7\u4e2d\u4f1a\u8f93\u51fa\u8b66\u544a\uff0cRedis\u5ffd\u7565\u6389AOF\u6587\u4ef6\u7684\u5c3e\u90e8\uff0c\u542f\u52a8\u6210\u529f\u3002aof-load-truncated\u53c2\u6570\u9ed8\u8ba4\u662f\u5f00\u542f\u7684\u3002<\/p>\n

RDB\u548cAOF\u4f18\u7f3a\u70b9<\/strong><\/div>\n
RDB\u7684\u4f18\u70b9\uff1f<\/strong><\/span><\/div>\n

RDB\u662f\u4e00\u4e2a\u975e\u5e38\u7d27\u51d1\uff08compact\uff09\u7684\u6587\u4ef6\uff0c\u4f53\u79ef\u5c0f\uff0c\u7f51\u7edc\u4f20\u8f93\u5feb\uff0c\u5b83\u4fdd\u5b58\u4e86Redis\u5728\u67d0\u4e2a\u65f6\u95f4\u70b9\u4e0a\u7684\u6570\u636e\u96c6\u3002\u8fd9\u79cd\u6587\u4ef6\u975e\u5e38\u9002\u5408\u7528\u4e8e\u8fdb\u884c\u5907\u4efd\uff0c\u6062\u590d\u901f\u5ea6\u6bd4AOF\u5feb\u5f88\u591a\u3002\u5f53\u7136\uff0c\u4e0eAOF\u76f8\u6bd4\uff0cRDB\u6700\u91cd\u8981\u7684\u4f18\u70b9\u4e4b\u4e00\u662f\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u76f8\u5bf9\u8f83\u5c0f\u3002\u7236\u8fdb\u7a0b\u5728\u4fdd\u5b58RDB\u6587\u4ef6\u65f6\u552f\u4e00\u8981\u505a\u7684\u5c31\u662ffork\u51fa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u7136\u540e\u8fd9\u4e2a\u5b50\u8fdb\u7a0b\u5c31\u4f1a\u5904\u7406\u63a5\u4e0b\u6765\u7684\u6240\u6709\u4fdd\u5b58\u5de5\u4f5c\uff0c\u7236\u8fdb\u7a0b\u65e0\u987b\u6267\u884c\u4efb\u4f55\u78c1\u76d8 I\/O \u64cd\u4f5c\u3002<\/p>\n

RDB\u7684\u7f3a\u70b9\uff1f<\/strong><\/span><\/div>\n

RDB\u6587\u4ef6\u7684\u81f4\u547d\u7f3a\u70b9\u5728\u4e8e\u5176\u6570\u636e\u5feb\u7167\u7684\u6301\u4e45\u5316\u65b9\u5f0f\u51b3\u5b9a\u4e86\u5fc5\u7136\u505a\u4e0d\u5230\u5b9e\u65f6\u6301\u4e45\u5316\uff0c\u800c\u5728\u6570\u636e\u8d8a\u6765\u8d8a\u91cd\u8981\u7684\u4eca\u5929\uff0c\u6570\u636e\u7684\u5927\u91cf\u4e22\u5931\u5f88\u591a\u65f6\u5019\u662f\u65e0\u6cd5\u63a5\u53d7\u7684\uff0c\u56e0\u6b64AOF\u6301\u4e45\u5316\u6210\u4e3a\u4e3b\u6d41\u3002\u6b64\u5916\uff0cRDB\u6587\u4ef6\u9700\u8981\u6ee1\u8db3\u7279\u5b9a\u683c\u5f0f\uff0c\u517c\u5bb9\u6027\u5dee\uff08\u5982\u8001\u7248\u672c\u7684Redis\u4e0d\u517c\u5bb9\u65b0\u7248\u672c\u7684RDB\u6587\u4ef6\uff09\u3002<\/p>\n

AOF\u7684\u4f18\u70b9?<\/strong><\/span><\/div>\n

\u4e0eRDB\u6301\u4e45\u5316\u76f8\u5bf9\u5e94\uff0cAOF\u7684\u4f18\u70b9\u5728\u4e8e\u652f\u6301\u79d2\u7ea7\u6301\u4e45\u5316\u3001\u517c\u5bb9\u6027\u597d\u3002\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u4e0d\u540c\u7684fsync\u7b56\u7565\uff0c\u6bd4\u5982\u65e0fsync\uff0c\u6bcf\u79d2\u949f\u4e00\u6b21fsync\uff0c\u6216\u8005\u6bcf\u6b21\u6267\u884c\u5199\u5165\u547d\u4ee4\u65f6fsync\u3002AOF\u7684\u9ed8\u8ba4\u7b56\u7565\u4e3a\u6bcf\u79d2\u949ffsync\u4e00\u6b21\uff0c\u5728\u8fd9\u79cd\u914d\u7f6e\u4e0b\uff0cRedis\u4ecd\u7136\u53ef\u4ee5\u4fdd\u6301\u826f\u597d\u7684\u6027\u80fd\uff0c\u5e76\u4e14\u5c31\u7b97\u53d1\u751f\u6545\u969c\u505c\u673a\uff0c\u4e5f\u6700\u591a\u53ea\u4f1a\u4e22\u5931\u4e00\u79d2\u949f\u7684\u6570\u636e\u3002AOF\u6587\u4ef6\u662f\u4e00\u4e2a\u53ea\u8fdb\u884c\u8ffd\u52a0\u64cd\u4f5c\u7684\u65e5\u5fd7\u6587\u4ef6\uff08append only log\uff09\uff0c\u56e0\u6b64\u5bf9AOF\u6587\u4ef6\u7684\u5199\u5165\u4e0d\u9700\u8981\u8fdb\u884cseek\uff08\u67e5\u627e\uff09\uff0c\u5373\u4f7f\u65e5\u5fd7\u56e0\u4e3a\u67d0\u4e9b\u539f\u56e0\u800c\u5305\u542b\u4e86\u672a\u5199\u5165\u5b8c\u6574\u7684\u547d\u4ee4\uff08\u6bd4\u5982\u5199\u5165\u65f6\u78c1\u76d8\u5df2\u6ee1\uff0c\u5199\u5165\u4e2d\u9014\u505c\u673a\uff0c\u7b49\u7b49\uff09\uff0c redis-check-aof \u5de5\u5177\u4e5f\u53ef\u4ee5\u8f7b\u6613\u5730\u4fee\u590d\u8fd9\u79cd\u95ee\u9898\u3002<\/p>\n

Redis\u53ef\u4ee5\u5728AOF\u6587\u4ef6\u4f53\u79ef\u53d8\u5f97\u8fc7\u5927\u65f6\uff0c\u81ea\u52a8\u5730\u5728\u540e\u53f0\u5bf9AOF\u8fdb\u884c\u91cd\u5199\uff1a \u91cd\u5199\u540e\u7684\u65b0AOF\u6587\u4ef6\u5305\u542b\u4e86\u6062\u590d\u5f53\u524d\u6570\u636e\u96c6\u6240\u9700\u7684\u6700\u5c0f\u547d\u4ee4\u96c6\u5408\u3002 \u6574\u4e2a\u91cd\u5199\u64cd\u4f5c\u662f\u7edd\u5bf9\u5b89\u5168\u7684\uff0c\u56e0\u4e3a Redis \u5728\u521b\u5efa\u65b0 AOF \u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u7ee7\u7eed\u5c06\u547d\u4ee4\u8ffd\u52a0\u5230\u73b0\u6709\u7684AOF\u6587\u4ef6\u91cc\u9762\uff0c\u5373\u4f7f\u91cd\u5199\u8fc7\u7a0b\u4e2d\u53d1\u751f\u505c\u673a\uff0c\u73b0\u6709\u7684AOF\u6587\u4ef6\u4e5f\u4e0d\u4f1a\u4e22\u5931\u3002 \u800c\u4e00\u65e6\u65b0AOF\u6587\u4ef6\u521b\u5efa\u5b8c\u6bd5\uff0cRedis\u5c31\u4f1a\u4ece\u65e7AOF\u6587\u4ef6\u5207\u6362\u5230\u65b0AOF\u6587\u4ef6\uff0c\u5e76\u5f00\u59cb\u5bf9\u65b0AOF\u6587\u4ef6\u8fdb\u884c\u8ffd\u52a0\u64cd\u4f5c\u3002AOF\u6587\u4ef6\u6709\u5e8f\u5730\u4fdd\u5b58\u4e86\u5bf9\u6570\u636e\u5e93\u6267\u884c\u7684\u6240\u6709\u5199\u5165\u64cd\u4f5c\uff0c\u8fd9\u4e9b\u5199\u5165\u64cd\u4f5c\u4ee5Redis\u534f\u8bae\u7684\u683c\u5f0f\u4fdd\u5b58\uff0c\u56e0\u6b64AOF\u6587\u4ef6\u7684\u5185\u5bb9\u975e\u5e38\u5bb9\u6613\u88ab\u4eba\u8bfb\u61c2\uff0c\u5bf9\u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff08parse\uff09\u4e5f\u5f88\u8f7b\u677e\u3002\u5bfc\u51fa\uff08export\uff09AOF\u6587\u4ef6\u4e5f\u975e\u5e38\u7b80\u5355\uff1a \u4e3e\u4e2a\u4f8b\u5b50\uff0c \u5982\u679c\u4f60\u4e0d\u5c0f\u5fc3\u6267\u884c\u4e86FLUSHALL\u547d\u4ee4\uff0c\u4f46\u53ea\u8981AOF\u6587\u4ef6\u672a\u88ab\u91cd\u5199\uff0c\u90a3\u4e48\u53ea\u8981\u505c\u6b62\u670d\u52a1\u5668\uff0c\u79fb\u9664AOF\u6587\u4ef6\u672b\u5c3e\u7684FLUSHALL\u547d\u4ee4\uff0c\u5e76\u91cd\u542f Redis\uff0c \u5c31\u53ef\u4ee5\u5c06\u6570\u636e\u96c6\u6062\u590d\u5230FLUSHALL\u6267\u884c\u4e4b\u524d\u7684\u72b6\u6001\u3002<\/p>\n

AOF\u7684\u7f3a\u70b9?<\/strong><\/span><\/div>\n

AOF\u6587\u4ef6\u7684\u4f53\u79ef\u901a\u5e38\u8981\u5927\u4e8eRDB\u6587\u4ef6\u7684\u4f53\u79ef\u3001\u4e14\u6062\u590d\u901f\u5ea6\u6162\u3002\u5bf9\u4e8e\u76f8\u540c\u7684\u6570\u636e\u96c6\u6765\u8bf4\uff0c\u6839\u636e\u6240\u4f7f\u7528\u7684fsync\u7b56\u7565\uff0cAOF\u7684\u901f\u5ea6\u53ef\u80fd\u4f1a\u6162\u4e8eRDB\u3002\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6bcf\u79d2fsync\u7684\u6027\u80fd\u4f9d\u7136\u975e\u5e38\u9ad8\uff0c\u800c\u5173\u95edfsync\u53ef\u4ee5\u8ba9AOF\u7684\u901f\u5ea6\u548cRDB\u4e00\u6837\u5feb\u3002\u53e6\u5916\uff0cAOF\u5728\u8fc7\u53bb\u66fe\u7ecf\u53d1\u751f\u8fc7\u8fd9\u6837\u7684bug\uff0c\u56e0\u4e3a\u4e2a\u522b\u547d\u4ee4\u7684\u539f\u56e0\uff0c\u5bfc\u81f4AOF\u6587\u4ef6\u5728\u91cd\u65b0\u8f7d\u5165\u65f6\uff0c\u65e0\u6cd5\u5c06\u6570\u636e\u96c6\u6062\u590d\u6210\u4fdd\u5b58\u65f6\u7684\u539f\u6837\u3002\u867d\u7136\u8fd9\u79cdbug\u5728AOF\u6587\u4ef6\u4e2d\u5e76\u4e0d\u5e38\u89c1\uff0c\u4f46\u662f\u5bf9\u6bd4\u6765\u8bf4\uff0cRDB\u51e0\u4e4e\u662f\u4e0d\u53ef\u80fd\u51fa\u73b0\u8fd9\u79cdbug\u7684\u3002<\/p>\n

RDB\u548cAOF\uff0c\u6211\u5e94\u8be5\u7528\u54ea\u4e00\u4e2a\uff1f<\/strong><\/span><\/div>\n

\u9996\u5148\u8981\u660e\u767d\u65e0\u8bba\u662fRDB\u8fd8\u662fAOF\uff0c\u6301\u4e45\u5316\u7684\u5f00\u542f\u90fd\u662f\u8981\u4ed8\u51fa\u6027\u80fd\u65b9\u9762\u4ee3\u4ef7\u7684\uff1a\u5bf9\u4e8eRDB\u6301\u4e45\u5316\uff0c\u4e00\u65b9\u9762\u662fbgsave\u5728\u8fdb\u884cfork\u64cd\u4f5c\u65f6Redis\u4e3b\u8fdb\u7a0b\u4f1a\u963b\u585e\uff0c\u53e6\u4e00\u65b9\u9762\uff0c\u5b50\u8fdb\u7a0b\u5411\u786c\u76d8\u5199\u6570\u636e\u4e5f\u4f1a\u5e26\u6765IO\u538b\u529b\u3002\u4f46\u5982\u679c\u4e1a\u52a1\u80fd\u5bb9\u5fcd\u51e0\u5206\u949f\u523010\u51e0\u5206\u949f\u7684\u6570\u636e\u4e22\u5931\uff08\u4e14\u4e0d\u4f7f\u7528\u5907\u5e93\uff09\uff0cRDB\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff1b\u4e0d\u7136\uff0c\u5c31\u9009\u62e9AOF\u3002<\/p>\n

\u5bf9\u4e8eAOF\u6301\u4e45\u5316\uff0c\u5411\u786c\u76d8\u5199\u6570\u636e\u7684\u9891\u7387\u5927\u5927\u63d0\u9ad8(everysec\u7b56\u7565\u4e0b\u4e3a\u79d2\u7ea7)\uff0cIO\u538b\u529b\u66f4\u5927\uff0c\u751a\u81f3\u53ef\u80fd\u9020\u6210AOF\u8ffd\u52a0\u963b\u585e\u95ee\u9898\uff08\u540e\u9762\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u79cd\u963b\u585e\uff09\uff0c\u6b64\u5916\uff0cAOF\u6587\u4ef6\u7684\u91cd\u5199\u4e0eRDB\u7684bgsave\u7c7b\u4f3c\uff0c\u4f1a\u6709fork\u65f6\u7684\u963b\u585e\u548c\u5b50\u8fdb\u7a0b\u7684IO\u538b\u529b\u95ee\u9898\u3002\u76f8\u5bf9\u6765\u8bf4\uff0c\u7531\u4e8eAOF\u5411\u786c\u76d8\u4e2d\u5199\u6570\u636e\u7684\u9891\u7387\u66f4\u9ad8\uff0c\u56e0\u6b64\u5bf9Redis\u4e3b\u8fdb\u7a0b\u6027\u80fd\u7684\u5f71\u54cd\u4f1a\u66f4\u5927\u3002<\/p>\n

\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u6839\u636e\u6570\u636e\u91cf\u3001\u5e94\u7528\u5bf9\u6570\u636e\u7684\u5b89\u5168\u8981\u6c42\u3001\u9884\u7b97\u9650\u5236\u7b49\u4e0d\u540c\u60c5\u51b5\uff0c\u4f1a\u6709\u5404\u79cd\u5404\u6837\u7684\u6301\u4e45\u5316\u7b56\u7565\uff1b\u5982\u5b8c\u5168\u4e0d\u4f7f\u7528\u4efb\u4f55\u6301\u4e45\u5316\u3001\u4f7f\u7528RDB\u6216AOF\u7684\u4e00\u79cd\uff0c\u6216\u540c\u65f6\u5f00\u542fRDB\u548cAOF\u6301\u4e45\u5316\u7b49\u3002\u6b64\u5916\uff0c\u6301\u4e45\u5316\u7684\u9009\u62e9\u5fc5\u987b\u4e0eRedis\u7684\u4e3b\u4ece\u7b56\u7565\u4e00\u8d77\u8003\u8651\uff0c\u56e0\u4e3a\u4e3b\u4ece\u590d\u5236\u4e0e\u6301\u4e45\u5316\u540c\u6837\u5177\u6709\u6570\u636e\u5907\u4efd\u7684\u529f\u80fd\uff0c\u800c\u4e14\u4e3b\u673amaster\u548c\u4ece\u673aslave\u53ef\u4ee5\u72ec\u7acb\u7684\u9009\u62e9\u6301\u4e45\u5316\u65b9\u6848\u3002\u6bd4\u5982\u5b8c\u5168\u5173\u95edmaster\u6301\u4e45\u5316\uff08\u5305\u62ecRDB\u548cAOF\uff09\uff0c\u8fd9\u6837\u53ef\u4ee5\u8ba9master\u7684\u6027\u80fd\u8fbe\u5230\u6700\u597d\uff1b\u800cslave\u53ef\u4ee5\u53ea\u5f00\u542fAOF\u3002\u4f46\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5982\u679cmaster\u670d\u52a1\u56e0\u4e3a\u6545\u969c\u5b95\u6389\u4e86\uff0c\u5982\u679c\u7cfb\u7edf\u4e2d\u6709\u81ea\u52a8\u62c9\u8d77\u673a\u5236\uff08\u5373\u68c0\u6d4b\u5230\u670d\u52a1\u505c\u6b62\u540e\u91cd\u542f\u8be5\u670d\u52a1\uff09\u5c06master\u81ea\u52a8\u91cd\u542f\uff0c\u7531\u4e8e\u6ca1\u6709\u6301\u4e45\u5316\u6587\u4ef6\uff0c\u90a3\u4e48master\u91cd\u542f\u540e\u6570\u636e\u662f\u7a7a\u7684\uff0cslave\u540c\u6b65\u6570\u636e\u4e5f\u53d8\u6210\u4e86\u7a7a\u7684\uff0c\u610f\u5473\u7740\u6570\u636e\u4e22\u5931\u3002\u6240\u4ee5\u5c3d\u91cf\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u51fa\u73b0\u3002<\/p>\n

RDB\u548cAOF\u4e4b\u95f4\u7684\u76f8\u4e92\u4f5c\u7528\uff1f<\/strong><\/span><\/div>\n

\u5728\u7248\u672c\u53f7\u5927\u4e8e\u7b49\u4e8e2.4\u7684Redis\u4e2d\uff0cBGSAVE\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u53ef\u4ee5\u6267\u884cBGREWRITEAOF\u3002\u53cd\u8fc7\u6765\u8bf4\uff0c\u5728BGREWRITEAOF\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e5f\u4e0d\u53ef\u4ee5\u6267\u884cBGSAVE\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u4e24\u4e2aRedis\u540e\u53f0\u8fdb\u7a0b\u540c\u65f6\u5bf9\u78c1\u76d8\u8fdb\u884c\u5927\u91cf\u7684I\/O\u64cd\u4f5c\u3002<\/p>\n

\u5982\u679cBGSAVE\u6b63\u5728\u6267\u884c\uff0c\u5e76\u4e14\u7528\u6237\u663e\u793a\u5730\u8c03\u7528BGREWRITEAOF\u547d\u4ee4\uff0c\u90a3\u4e48\u670d\u52a1\u5668\u5c06\u5411\u7528\u6237\u56de\u590d\u4e00\u4e2aOK\u72b6\u6001\uff0c\u5e76\u544a\u77e5\u7528\u6237\uff0cBGREWRITEAOF\u5df2\u7ecf\u88ab\u9884\u5b9a\u6267\u884c\uff1a \u4e00\u65e6BGSAVE\u6267\u884c\u5b8c\u6bd5\uff0cBGREWRITEAOF\u5c31\u4f1a\u6b63\u5f0f\u5f00\u59cb\u3002\u5f53Redis\u542f\u52a8\u65f6\uff0c\u5982\u679cRDB\u6301\u4e45\u5316\u548cAOF\u6301\u4e45\u5316\u90fd\u88ab\u6253\u5f00\u4e86\uff0c\u90a3\u4e48\u7a0b\u5e8f\u4f1a\u4f18\u5148\u4f7f\u7528AOF\u6587\u4ef6\u6765\u6062\u590d\u6570\u636e\u96c6\uff0c\u56e0\u4e3aAOF\u6587\u4ef6\u6240\u4fdd\u5b58\u7684\u6570\u636e\u901a\u5e38\u662f\u6700\u5b8c\u6574\u7684\u3002<\/p>\n

RDB\u548cAOF\u6570\u636e\u5bfc\u5165<\/strong><\/div>\n

\u8fd9\u4e9b\u6301\u4e45\u5316\u7684\u6570\u636e\u6709\u4ec0\u4e48\u7528\uff0c\u5f53\u7136\u662f\u7528\u4e8e\u91cd\u542f\u540e\u7684\u6570\u636e\u6062\u590d\u3002Redis\u662f\u4e00\u4e2a\u5185\u5b58\u6570\u636e\u5e93\uff0c\u65e0\u8bba\u662fRDB\u8fd8\u662fAOF\uff0c\u90fd\u53ea\u662f\u5176\u4fdd\u8bc1\u6570\u636e\u6062\u590d\u7684\u63aa\u65bd\u3002\u6240\u4ee5Redis\u5728\u5229\u7528RDB\u6216AOF\u8fdb\u884c\u6062\u590d\u7684\u65f6\u5019\uff0c\u4f1a\u8bfb\u53d6RDB\u6216AOF\u6587\u4ef6\uff0c\u91cd\u65b0\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u76f8\u5bf9\u4e8eMySQL\u7b49\u6570\u636e\u5e93\u7684\u542f\u52a8\u65f6\u95f4\u6765\u8bf4\uff0c\u4f1a\u957f\u5f88\u591a\uff0c\u56e0\u4e3aMySQL\u672c\u6765\u662f\u4e0d\u9700\u8981\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u7684\u3002<\/p>\n

\u4f46\u662f\u76f8\u5bf9\u6765\u8bf4\uff0cMySQL\u542f\u52a8\u540e\u63d0\u4f9b\u670d\u52a1\u65f6\uff0c\u5176\u88ab\u8bbf\u95ee\u7684\u70ed\u6570\u636e\u4e5f\u4f1a\u6162\u6162\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u901a\u5e38\u6211\u4eec\u79f0\u4e4b\u4e3a\u9884\u70ed\uff0c\u800c\u5728\u9884\u70ed\u5b8c\u6210\u524d\uff0c\u5176\u6027\u80fd\u90fd\u4e0d\u4f1a\u592a\u9ad8\u3002\u800cRedis\u7684\u597d\u5904\u662f\u4e00\u6b21\u6027\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u4e00\u6b21\u6027\u9884\u70ed\u3002\u8fd9\u6837\u53ea\u8981Redis\u542f\u52a8\u5b8c\u6210\uff0c\u90a3\u4e48\u5176\u63d0\u4f9b\u670d\u52a1\u7684\u901f\u5ea6\u90fd\u662f\u975e\u5e38\u5feb\u7684\u3002<\/p>\n

\u800c\u5728\u5229\u7528RDB\u548c\u5229\u7528AOF\u542f\u52a8\u4e0a\uff0c\u5176\u542f\u52a8\u65f6\u95f4\u6709\u4e00\u4e9b\u5dee\u522b\u3002RDB\u7684\u542f\u52a8\u65f6\u95f4\u4f1a\u66f4\u77ed\uff0c\u539f\u56e0\u6709\u4e24\u4e2a\uff0c\u4e00\u662fRDB\u6587\u4ef6\u4e2d\u6bcf\u4e00\u6761\u6570\u636e\u53ea\u6709\u4e00\u6761\u8bb0\u5f55\uff0c\u4e0d\u4f1a\u50cfAOF\u65e5\u5fd7\u90a3\u6837\u53ef\u80fd\u6709\u4e00\u6761\u6570\u636e\u7684\u591a\u6b21\u64cd\u4f5c\u8bb0\u5f55\u3002\u6240\u4ee5\u6bcf\u6761\u6570\u636e\u53ea\u9700\u8981\u5199\u4e00\u6b21\u5c31\u884c\u4e86\u3002\u53e6\u4e00\u4e2a\u539f\u56e0\u662fRDB\u6587\u4ef6\u7684\u5b58\u50a8\u683c\u5f0f\u548cRedis\u6570\u636e\u5728\u5185\u5b58\u4e2d\u7684\u7f16\u7801\u683c\u5f0f\u662f\u4e00\u81f4\u7684\uff0c\u4e0d\u9700\u8981\u518d\u8fdb\u884c\u6570\u636e\u7f16\u7801\u5de5\u4f5c\u3002\u5728CPU\u6d88\u8017\u4e0a\u8981\u8fdc\u5c0f\u4e8eAOF\u65e5\u5fd7\u7684\u52a0\u8f7d\u3002<\/p>\n

\u6ce8\u610f\uff1a\u5f53redis\u542f\u52a8\u65f6\uff0c\u5982\u679crdb\u6301\u4e45\u5316\u548caof\u6301\u4e45\u5316\u90fd\u6253\u5f00\u4e86\uff0c\u90a3\u4e48\u7a0b\u5e8f\u4f1a\u4f18\u5148\u4f7f\u7528aof\u65b9\u5f0f\u6765\u6062\u590d\u6570\u636e\u96c6\uff0c\u56e0\u4e3aaof\u65b9\u5f0f\u6240\u4fdd\u5b58\u7684\u6570\u636e\u901a\u5e38\u662f\u6700\u5b8c\u6574\u7684\u3002\u5982\u679caof\u6587\u4ef6\u4e22\u5931\u4e86\uff0c\u5219\u542f\u52a8\u4e4b\u540e\u6570\u636e\u5e93\u5185\u5bb9\u4e3a\u7a7a\u3002<\/p>\n

\u6ce8\u610f\uff1a\u5982\u679c\u60f3\u628a\u6b63\u5728\u8fd0\u884c\u7684redis\u6570\u636e\u5e93\uff0c\u4eceRDB\u5207\u6362\u5230AOF\uff0c\u5efa\u8bae\u5148\u4f7f\u7528\u52a8\u6001\u5207\u6362\u65b9\u5f0f\uff0c\u518d\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u91cd\u542f\u6570\u636e\u5e93\u3002(\u4e0d\u80fd\u76f4\u63a5\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u91cd\u542f\u6570\u636e\u5e93\uff0c\u5426\u5219\u6570\u636e\u5e93\u4e2d\u6570\u636e\u5c31\u4e3a\u7a7a\u4e86\u3002)
\n\u5728Redis 2.2\u6216\u4ee5\u4e0a\u7248\u672c\uff0c\u53ef\u4ee5\u5728\u4e0d\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\uff0c\u4eceRDB\u5207\u6362\u5230AOF \uff1a<\/p>\n

\u4e3a\u6700\u65b0\u7684dump.rdb\u6587\u4ef6\u521b\u5efa\u4e00\u4e2a\u5907\u4efd\uff0c\u5c06\u5907\u4efd\u653e\u5230\u4e00\u4e2a\u5b89\u5168\u7684\u5730\u65b9\u3002\u6267\u884c\u4ee5\u4e0b\u4e24\u6761\u547d\u4ee4\uff1a<\/p>\n

\r\n127.0.0.1:6379> CONFIG SET dir \/apps\/redis\/data\/redis-8836\r\n127.0.0.1:6379> CONFIG SET appendonly yes\r\n127.0.0.1:6379> CONFIG SET save \"\"\r\n<\/pre>\n

\u786e\u4fdd\u547d\u4ee4\u6267\u884c\u4e4b\u540e\uff0c\u6570\u636e\u5e93\u7684\u952e\u7684\u6570\u91cf\u6ca1\u6709\u6539\u53d8\u3002\u786e\u4fdd\u5199\u547d\u4ee4\u4f1a\u88ab\u6b63\u786e\u5730\u8ffd\u52a0\u5230 AOF \u6587\u4ef6\u7684\u672b\u5c3e\u3002<\/p>\n

\u6b65\u9aa42\u662f\u5f00\u542f\u4e86AOF\u529f\u80fd\uff0cRedis\u4f1a\u963b\u585e\u76f4\u5230\u521d\u59cbAOF\u6587\u4ef6\u521b\u5efa\u5b8c\u6210\u4e3a\u6b62\uff0c\u4e4b\u540eRedis\u4f1a\u7ee7\u7eed\u5904\u7406\u547d\u4ee4\u8bf7\u6c42\uff0c\u5e76\u5f00\u59cb\u5c06\u5199\u5165\u547d\u4ee4\u8ffd\u52a0\u5230AOF\u6587\u4ef6\u672b\u5c3e\u3002<\/p>\n

\u6b65\u9aa43\u7528\u4e8e\u5173\u95edRDB\u529f\u80fd\uff0c\u8fd9\u4e00\u6b65\u662f\u53ef\u9009\u7684\uff0c\u5982\u679c\u4f60\u613f\u610f\u7684\u8bdd\uff0c\u4e5f\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528RDB\u548cAOF\u8fd9\u4e24\u79cd\u6301\u4e45\u5316\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Redis\u662f\u5185\u5b58\u6570\u636e\u5e93\uff0c\u6570\u636e\u90fd\u662f\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u4e3a\u4e86\u907f\u514d\u8fdb\u7a0b\u9000\u51fa\u5bfc\u81f4\u6570\u636e\u7684\u6c38\u4e45\u4e22\u5931\uff0c\u9700\u8981\u5b9a\u671f\u5c06Redis\u4e2d\u7684\u6570\u636e […]<\/p>\n","protected":false},"author":668,"featured_media":7719,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-136058","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/136058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=136058"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/136058\/revisions"}],"predecessor-version":[{"id":136549,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/136058\/revisions\/136549"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/7719"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=136058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=136058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=136058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}