{"id":201479,"date":"2025-05-10T09:57:55","date_gmt":"2025-05-10T01:57:55","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201479\/"},"modified":"2025-05-10T09:57:55","modified_gmt":"2025-05-10T01:57:55","slug":"%e4%bd%a0%e8%af%b4%e4%bd%a0%e7%b2%be%e9%80%9a-redis%ef%bc%8c%e4%bd%a0%e7%9c%8b%e8%bf%87%e6%8c%81%e4%b9%85%e5%8c%96%e7%9a%84%e9%85%8d%e7%bd%ae%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201479\/","title":{"rendered":"\u4f60\u8bf4\u4f60\u7cbe\u901a Redis\uff0c\u4f60\u770b\u8fc7\u6301\u4e45\u5316\u7684\u914d\u7f6e\u5417\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4f60\u8bf4\u4f60\u7cbe\u901a Redis\uff0c\u4f60\u770b\u8fc7\u6301\u4e45\u5316\u7684\u914d\u7f6e\u5417\uff1f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5728\u6570\u636e\u5e93\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929golang\u5b66\u4e60\u7f51\u5c31\u6574\u7406\u5206\u4eab\u300a\u4f60\u8bf4\u4f60\u7cbe\u901a Redis\uff0c\u4f60\u770b\u8fc7\u6301\u4e45\u5316\u7684\u914d\u7f6e\u5417\uff1f\u300b\uff0c\u804a\u804aRedis\u3001\u914d\u7f6e\u3001\u5f00\u53d1\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002<\/p>\n<\/p>\n<p>\u6211\u4eec\u4e4b\u524d\u4ecb\u7ecd\u4e86&nbsp;<code>Redis<\/code>&nbsp;<strong>\u4e94\u79cd\u6570\u636e\u7c7b\u578b\u7684\u547d\u4ee4<\/strong>&nbsp;\u4e0e&nbsp;<strong>\u914d\u7f6e\u6587\u4ef6\u7684\u57fa\u672c\u914d\u7f6e<\/strong>&nbsp;\uff0c\u4eca\u5929\u8ba9\u6211\u4eec\u4ece\u7406\u8bba\u548c\u914d\u7f6e\u4e24\u4e2a\u5c42\u9762\u6765\u63ed\u5f00&nbsp;<code>Redis<\/code>&nbsp;\u6301\u4e45\u5316\u7684\u795e\u79d8\u9762\u7eb1\u3002<\/p>\n<p>\u6240\u8c13\u6301\u4e45\u5316\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\u5c06\u5185\u5b58\u4e2d\u7684\u6570\u636e\u4fdd\u5b58\u5230\u786c\u76d8\u4e0a\u5b58\u50a8\u7684\u8fc7\u7a0b\u3002\u6301\u4e45\u5316\u4e4b\u540e\u7684\u6570\u636e\u5728\u7cfb\u7edf\u91cd\u542f\u6216\u8005\u5b95\u673a\u4e4b\u540e\u4f9d\u7136\u53ef\u4ee5\u8fdb\u884c\u8bbf\u95ee\uff0c\u4fdd\u8bc1\u4e86\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p><code>Redis<\/code>&nbsp;\u6709\u4e24\u79cd\u6301\u4e45\u5316\u65b9\u6848\uff0c\u4e00\u79cd\u662f\u5feb\u7167\u65b9\u5f0f\uff08&nbsp;<code>SNAPSHOTTING<\/code>&nbsp;\uff09\uff0c\u7b80\u79f0&nbsp;<code>RDB<\/code>&nbsp;\uff1b\u4e00\u79cd\u662f\u53ea\u8ffd\u52a0\u6a21\u5f0f\uff08&nbsp;<code>APPEND ONLY MODE<\/code>&nbsp;\uff09\uff0c\u79f0\u4e3aAOF\u3002\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u5206\u522b\u4e86\u89e3\u4e00\u4e0b\u5b83\u4eec\u7684\u4f7f\u7528\u4e0e\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<h2>RDB<\/h2>\n<p><code>RDB<\/code>&nbsp;\u4e3a&nbsp;<code>Redis DataBase<\/code>&nbsp;\u7684\u7f29\u5199\uff0c\u662f&nbsp;<code>Redis<\/code>&nbsp;\u9ed8\u8ba4\u7684\u6301\u4e45\u5316\u65b9\u6848\u3002\u5b83\u80fd\u591f\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5185\u5c06\u5185\u5b58\u6570\u636e\u96c6\u5feb\u7167\uff08&nbsp;<code>snapshot<\/code>&nbsp;\uff09\u5199\u5165\u78c1\u76d8\uff0c\u6062\u590d\u65f6\u5c06\u5feb\u7167\u6587\u4ef6\uff08&nbsp;<code>dump.rdb<\/code>&nbsp;\uff09\u8bfb\u56de\u5185\u5b58\u3002<\/p>\n<\/p>\n<p>\u6211\u4eec\u5148\u6765\u6252\u4e00\u4e0b\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684&nbsp;<code>SNAPSHOTTING<\/code>&nbsp;:<\/p>\n<h3>\u914d\u7f6e\u6587\u4ef6<\/h3>\n<h4>save&nbsp;<code> <\/code><\/h4>\n<p>\u5728\u7ed9\u5b9a\u7684&nbsp;<strong>\u79d2\u6570<\/strong>&nbsp;\u5185\uff0c\u5982\u679c\u5bf9\u6570\u636e\u5e93\u6267\u884c\u7684&nbsp;<strong>\u5199\u5165\u64cd\u4f5c\u6570<\/strong>&nbsp;\u8fbe\u5230\u8bbe\u5b9a\u7684\u503c\uff0c\u5219\u5c06\u6570\u636e\u540c\u6b65\u5230\u6570\u636e\u6587\u4ef6\u3002\u652f\u6301\u591a\u4e2a\u6761\u4ef6\u914d\u5408\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u4e2d\u63d0\u4f9b\u4e86\u4e09\u4e2a\u6761\u4ef6\uff1a<\/p>\n<\/p>\n<ol>\n<li><span><span>save&nbsp;<\/span><span>900<\/span><span>&nbsp;<\/span><span>1<\/span><span>&nbsp;<\/span><span>\/\/900s\u5185\u67091\u4e2a\u66f4\u6539<\/span><span>&nbsp;<\/span><\/span><\/li>\n<li><span>save&nbsp;<span>300<\/span><span>&nbsp;<\/span><span>10<\/span><span>&nbsp;<\/span><span>\/\/300s\u5185\u670910\u4e2a\u66f4\u6539<\/span><span>&nbsp;<\/span><\/span><\/li>\n<li><span>save&nbsp;<span>60<\/span><span>&nbsp;<\/span><span>10000<\/span><span>&nbsp;<\/span><span>\/\/60s\u5185\u670910000\u6b21\u66f4\u6539<\/span><span>&nbsp;<\/span><\/span><\/li>\n<\/ol>\n<p>\u6ce8\u610f\uff1a\u82e5\u4e0d\u60f3\u7528&nbsp;<code>RDB<\/code>&nbsp;\u65b9\u6848\uff0c\u53ef\u4ee5\u628a&nbsp;<code>save \"\"<\/code>&nbsp;\u7684\u6ce8\u91ca\u6253\u5f00\uff0c\u4e0a\u8fb9\u4e09\u4e2a\u6ce8\u91ca\u6389\u3002<\/p>\n<h4>stop-writes-on-bgsave-error yes<\/h4>\n<p>\u5f53&nbsp;<code>bgsave<\/code>&nbsp;\u51fa\u73b0\u9519\u8bef\u65f6\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u662f\u5426\u505c\u6b62\u6267\u884c\u5199\u547d\u4ee4\uff1b<\/p>\n<ul>\n<li>\u5982\u679c\u4e3a&nbsp;<code>yes<\/code>&nbsp;\uff0c\u5219\u5f53\u786c\u76d8\u51fa\u73b0\u95ee\u9898\u65f6\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u5c06\u505c\u6b62\u63a5\u53d7\u5199\u5165\u64cd\u4f5c\uff0c\u8fd9\u6837\u6211\u4eec\u53ef\u4ee5\u53ca\u65f6\u53d1\u73b0\uff0c\u907f\u514d\u6570\u636e\u7684\u5927\u91cf\u4e22\u5931\uff1b<\/li>\n<li>&nbsp;<\/li>\n<\/ul>\n<ol>\n<li><span><span>no&nbsp;<\/span><\/span><\/li>\n<li><span>Redis&nbsp;<\/span><\/li>\n<li><span>bgsave&nbsp;<\/span><\/li>\n<\/ol>\n<p>\u5982\u679c\u5df2\u7ecf\u8bbe\u7f6e\u4e86\u5bf9&nbsp;<code>Redis<\/code>&nbsp;\u670d\u52a1\u5668\u7684\u6b63\u786e\u76d1\u89c6\u548c\u6301\u4e45\u6027\uff0c\u5373\u91c7\u7528\u4e86\u5176\u4ed6\u624b\u6bb5\u53d1\u73b0\u548c\u63a7\u5236\u6570\u636e\u5b8c\u6574\u6027\uff0c\u53ef\u80fd\u5e0c\u671b\u7981\u7528\u6b64\u529f\u80fd\uff0c\u4ee5\u4fbf\u5373\u4f7f\u5728\u78c1\u76d8\u3001\u6743\u9650\u7b49\u65b9\u9762\u51fa\u73b0\u95ee\u9898\u65f6\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u4ecd\u80fd\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u5982\u679c\u540e\u53f0\u4fdd\u5b58\u8fc7\u7a0b\u5c06\u518d\u6b21\u5f00\u59cb\u5de5\u4f5c\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u5c06\u81ea\u52a8\u5141\u8bb8\u518d\u6b21\u5199\u5165\u3002<\/p>\n<h4>rdbcompression yes<\/h4>\n<p>\u6307\u5b9a\u5b58\u50a8\u5230\u672c\u5730\u6570\u636e\u5e93\u65f6\u662f\u5426&nbsp;<strong>\u538b\u7f29<\/strong>&nbsp;\uff08&nbsp;<code>Redis<\/code>&nbsp;\u91c7\u7528&nbsp;<code>LZF<\/code>&nbsp;\u538b\u7f29\uff09\u6570\u636e\uff0c\u9ed8\u8ba4\u4e3a&nbsp;<code>yes<\/code>&nbsp;\u3002\u5982\u679c\u4e3a\u4e86\u8282\u7701&nbsp;<code>CPU<\/code>&nbsp;\u65f6\u95f4\uff0c\u53ef\u4ee5\u5173\u95ed\u8be5\u9009\u9879\uff0c\u4f46\u4f1a\u5bfc\u81f4\u6570\u636e\u5e93\u6587\u4ef6\u53d8\u5f97\u5de8\u5927\u3002<\/p>\n<h4>rdbchecksum yes<\/h4>\n<p>\u4ece&nbsp;<code>RDB<\/code>&nbsp;\u7248\u672c&nbsp;<code>5<\/code>&nbsp;\u5f00\u59cb\uff0c\u5728\u5b58\u50a8\u5feb\u7167\u540e\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528&nbsp;<code>CRC64<\/code>&nbsp;\u7b97\u6cd5\u6765\u8fdb\u884c\u6570\u636e\u6821\u9a8c\uff0c&nbsp;<code>CRC64<\/code>&nbsp;\u6821\u9a8c\u653e\u5728\u6587\u4ef6\u7684\u672b\u5c3e\u3002\u5f00\u542f\u4e4b\u540e\uff0c\u4fdd\u5b58\u548c\u52a0\u8f7d&nbsp;<code>RDB<\/code>&nbsp;\u6587\u4ef6\u65f6\u4f1a\u589e\u52a0\u5927\u7ea6&nbsp;<code>10%<\/code>&nbsp;\u7684\u6027\u80fd\u6d88\u8017\uff0c\u5982\u679c\u5e0c\u671b\u83b7\u53d6\u5230\u6700\u5927\u7684\u6027\u80fd\u63d0\u5347\uff0c\u53ef\u4ee5\u5173\u95ed\u6b64\u529f\u80fd\u3002<\/p>\n<p>\u7981\u7528&nbsp;<strong>\u6821\u9a8c\u548c<\/strong>&nbsp;\u521b\u5efa\u7684&nbsp;<code>RDB<\/code>&nbsp;\u6587\u4ef6\u7684\u6821\u9a8c\u548c\u4e3a\u96f6\uff0c\u8fd9\u5c06\u544a\u8bc9\u52a0\u8f7d\u4ee3\u7801\u8df3\u8fc7\u68c0\u67e5\u3002<\/p>\n<h4>dbfilename dump.rdb<\/h4>\n<p>\u6307\u5b9a\u672c\u5730\u6570\u636e\u5e93\u6587\u4ef6\u540d\uff0c\u91cd\u542f\u4e4b\u540e\u81ea\u52a8\u52a0\u8f7d\u8fdb&nbsp;<strong>\u5185\u5b58<\/strong>&nbsp;\uff0c\u624b\u52a8\u6267\u884c&nbsp;<code>save<\/code>&nbsp;\u547d\u4ee4\u7684\u8bdd\u5373\u523b\u751f\u6548\u3002<\/p>\n<p>\u5927\u5751\u8bf7\u6ce8\u610f\uff1a&nbsp;<code>flushall<\/code>&nbsp;\u3001&nbsp;<code>shutdown<\/code>&nbsp;\u547d\u4ee4\u90fd\u4f1a\u6e05\u7a7a\u5e76\u63d0\u4ea4\u81f3&nbsp;<code>dump.rdb<\/code><\/p>\n<h4>dir .\/<\/h4>\n<p>\u6307\u5b9a\u672c\u5730\u6570\u636e\u5e93\u5b58\u653e\u76ee\u5f55\u3002<\/p>\n<h3>\u7406\u8bba<\/h3>\n<h4>\u5de5\u4f5c\u65b9\u5f0f<\/h4>\n<ul>\n<li>&nbsp;<\/li>\n<\/ul>\n<ol>\n<li><span><span>Redis&nbsp;<\/span><\/span><\/li>\n<li><span>dump.rdb&nbsp;<\/span><\/li>\n<li><span>fork()&nbsp;<\/span><\/li>\n<\/ol>\n<li>\u5b50\u8fdb\u7a0b\u5c06\u6570\u636e\u96c6\u5199\u5165\u4e34\u65f6\u6587\u4ef6&nbsp;<code>RDB<\/code>&nbsp;\u4e2d\uff1b<\/li>\n<li>&nbsp;<\/li>\n<ol>\n<li><span><span>RDB&nbsp;<\/span><\/span><\/li>\n<li><span>Redis&nbsp;<\/span><\/li>\n<li><span>RDB&nbsp;<\/span><\/li>\n<li><span>RDB&nbsp;<\/span><\/li>\n<li><span>RDB&nbsp;<\/span><\/li>\n<\/ol>\n<p>\u8fd9\u79cd\u5de5\u4f5c\u65b9\u5f0f\u4f7f\u5f97&nbsp;<code>Redis<\/code>&nbsp;\u53ef\u4ee5\u4ece\u5199\u65f6\u590d\u5236\uff08&nbsp;<code>copy-on-write<\/code>&nbsp;\uff09\u673a\u5236\u4e2d\u83b7\u76ca\u3002<\/p>\n<h4>\u5982\u4f55\u89e6\u53d1RDB\u5feb\u7167<\/h4>\n<ol>\n<li>\n<p>\u914d\u7f6e\u6587\u4ef6\u4e2d\u9ed8\u8ba4\u7684\u5feb\u7167\u914d\u7f6e\uff1b<\/p>\n<\/li>\n<li>\u547d\u4ee4&nbsp;<code>save<\/code>&nbsp;\uff08\u963b\u585e\uff0c \u53ea\u7ba1\u4fdd\u5b58\u5feb\u7167\uff0c\u5176\u4ed6\u7684\u7b49\u5f85\uff09\u6216\u8005\u662f&nbsp;<code>bgsave<\/code>&nbsp;\uff08\u5f02\u6b65\uff09\u547d\u4ee4\uff0c\u5feb\u7167\u540c\u65f6\u8fd8\u53ef\u4ee5\u54cd\u5e94\u5ba2\u6237\u7aef\u547d\u4ee4\uff1b<\/li>\n<li>\u6267\u884c&nbsp;<code>flushall<\/code>&nbsp;\u547d\u4ee4\uff0c\u6e05\u7a7a\u6570\u636e\u5e93\u6240\u6709\u6570\u636e\uff0c\u610f\u4e49\u4e0d\u5927;<\/li>\n<li>\u6267\u884c&nbsp;<code>shutdown<\/code>&nbsp;\u547d\u4ee4\uff0c\u4fdd\u8bc1\u670d\u52a1\u5668\u6b63\u5e38\u5173\u95ed\u4e14\u4e0d\u4e22\u5931\u4efb\u4f55\u6570\u636e\uff0c\u610f\u4e49\u4e5f\u4e0d\u5927\u3002<\/li>\n<\/ol>\n<h4>\u901a\u8fc7RDB\u6587\u4ef6\u6062\u590d\u6570\u636e<\/h4>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u4e00\u822c\u4f1a\u8003\u8651\u5230\u7269\u7406\u673a\u786c\u76d8\u635f\u574f\u7684\u60c5\u51b5\uff0c\u6240\u4ee5\u6211\u4eec\u4f1a\u9009\u62e9\u5907\u4efd&nbsp;<code>dump.rdb<\/code>&nbsp;\u6587\u4ef6\u3002\u5c06\u5907\u4efd\u7684&nbsp;<code>dump.rdb<\/code>&nbsp;\u6587\u4ef6\u62f7\u8d1d\u5230&nbsp;<code>redis<\/code>&nbsp;\u7684\u5b89\u88c5\u76ee\u5f55\u7684&nbsp;<code>bin<\/code>&nbsp;\u76ee\u5f55\u4e0b\uff0c\u91cd\u542f&nbsp;<code>redis<\/code>&nbsp;\u670d\u52a1\u5373\u53ef\u3002<\/p>\n<h4>\u4f18\u70b9<\/h4>\n<ul>\n<li><code>RDB<\/code>&nbsp;\u662f\u4e00\u4e2a\u975e\u5e38\u7d27\u51d1\u7684\u6587\u4ef6\uff0c\u975e\u5e38\u9002\u7528\u4e8e\u6570\u636e\u96c6\u7684\u5907\u4efd\uff1b<\/li>\n<li><code>RDB<\/code>&nbsp;\u662f\u4e00\u4e2a\u7d27\u51d1\u7684\u5355\u4e00\u6587\u4ef6\uff0c\u5f88\u65b9\u4fbf\u4f20\u9001\u5230\u53e6\u4e00\u4e2a\u8fdc\u7aef\u6570\u636e\u4e2d\u5fc3\u6216\u8005\u4e9a\u9a6c\u900a\u7684S3\uff08\u53ef\u80fd\u52a0\u5bc6\uff09\uff0c\u975e\u5e38\u9002\u7528\u4e8e\u707e\u96be\u6062\u590d\uff1b<\/li>\n<li><code>Redis<\/code>&nbsp;\u7684\u4e3b\u8fdb\u7a0b\u4e0d\u8fdb\u884c&nbsp;<code>I\/O<\/code>&nbsp;\u64cd\u4f5c\uff0c\u786e\u4fdd\u4e86\u6781\u9ad8\u7684\u6027\u80fd\uff1b<\/li>\n<li>\u9002\u5408\u5927\u89c4\u6a21\u6570\u636e\u7684\u6062\u590d\uff0c\u5bf9\u4e8e\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\u8981\u6c42\u4e0d\u9ad8\u7684\u8bdd\uff0c&nbsp;<code>RDB<\/code>&nbsp;\u6bd4&nbsp;<code>AOF<\/code>&nbsp;\u65b9\u5f0f\u66f4\u52a0\u9ad8\u6548\u3002<\/li>\n<\/ul>\n<h4>\u7f3a\u70b9<\/h4>\n<ul>\n<li>\u5728&nbsp;<code>Redis<\/code>&nbsp;\u610f\u5916\u5b95\u673a\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u4e22\u5931\u51e0\u5206\u949f\u7684\u6570\u636e\uff1b<\/li>\n<li>&nbsp;<\/li>\n<\/ul>\n<ol>\n<li><span><span>RDB&nbsp;<\/span><\/span><\/li>\n<li><span>fork&nbsp;<\/span><\/li>\n<li><span>fork&nbsp;<\/span><\/li>\n<li><span>Redis&nbsp;<\/span><\/li>\n<li><span>CPU&nbsp;<\/span><\/li>\n<li><span>AOF&nbsp;<\/span><\/li>\n<li><span>fork&nbsp;<\/span><\/li>\n<\/ol>\n<h2>AOF<\/h2>\n<p>\u4e3a\u4e86\u89e3\u51b3&nbsp;<code>RDB<\/code>&nbsp;\u65b9\u5f0f\u5728\u5b95\u673a\u65f6\u4e22\u5931\u6570\u636e\u8fc7\u591a\u7684\u95ee\u9898\uff0c\u4ece&nbsp;<code>1.1<\/code>&nbsp;\u7248\u672c\u5f00\u59cb\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u589e\u52a0\u4e86\u4e00\u79cd&nbsp;<code>durable<\/code>&nbsp;\u7684\u6301\u4e45\u5316\u65b9\u5f0f\uff1a&nbsp;<code>AOF<\/code>&nbsp;\u3002<\/p>\n<p><code>AOF<\/code>&nbsp;\u662f&nbsp;<code>Append Only File<\/code>&nbsp;\u7684\u7f29\u5199\uff0c\u9ed8\u8ba4\u4e0d\u5f00\u542f\u3002&nbsp;<code>AOF<\/code>&nbsp;\u4ee5\u65e5\u5fd7\u7684\u5f62\u5f0f\u6765\u8bb0\u5f55\u6bcf\u4e2a\u5199\u64cd\u4f5c\uff0c\u53ea\u5141\u8bb8\u8ffd\u52a0\u6587\u4ef6\u4f46\u4e0d\u53ef\u4ee5\u6539\u5199\u6587\u4ef6\uff0c\u5f53\u670d\u52a1\u5668\u91cd\u542f\u7684\u65f6\u5019\u4f1a\u91cd\u65b0\u6267\u884c\u8fd9\u4e9b\u547d\u4ee4\u6765\u6062\u590d\u539f\u59cb\u7684\u6570\u636e\u3002<\/p>\n<p>\u6211\u4eec\u518d\u6765\u770b\u4e00\u4e0b\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684&nbsp;<code>APPEND ONLY MODE<\/code>&nbsp;:<\/p>\n<h3>\u914d\u7f6e\u6587\u4ef6<\/h3>\n<h4>appendonly no<\/h4>\n<p>\u9ed8\u8ba4\u4e3a\u5173\u95ed\u72b6\u6001\uff0c\u6539\u4e3a&nbsp;<code>yes<\/code>&nbsp;\u6253\u5f00\u6301\u4e45\u5316\u3002&nbsp;<code>AOF<\/code>&nbsp;\u548c&nbsp;<code>RDB<\/code>&nbsp;\u53ef\u4ee5\u540c\u65f6\u542f\u7528\u800c\u4e0d\u4f1a\u51fa\u73b0\u95ee\u9898\u3002<\/p>\n<h4>appendfilename &#8220;appendonly.aof&#8221;<\/h4>\n<p>\u6587\u4ef6\u9ed8\u8ba4\u540d\u79f0\uff0c\u542f\u52a8\u5373\u521b\u5efa\u3002\u52a0\u8f7d&nbsp;<strong>\u5148\u4e8e<\/strong>&nbsp;<code>dump.rdb<\/code>&nbsp;\u6587\u4ef6<\/p>\n<h4>appendfsync<\/h4>\n<p>\u540c\u6b65\u7b56\u7565\uff1a\u7cfb\u7edf\u51fd\u6570&nbsp;<code>fsync()<\/code>&nbsp;\u544a\u8bc9\u64cd\u4f5c\u7cfb\u7edf\u5728\u78c1\u76d8\u4e0a\u5b9e\u9645\u5199\u5165\u6570\u636e\u3002&nbsp;<code>Redis<\/code>&nbsp;\u652f\u6301\u4e09\u79cd\u4e0d\u540c\u7684\u6a21\u5f0f<\/p>\n<\/p>\n<ol>\n<li><span><span>appendfsync&nbsp;always&nbsp;<\/span><span>\/\/\u6bcf\u6b21\u53d1\u751f\u6570\u636e\u53d8\u66f4\u4f1a\u88ab\u7acb\u5373\u8bb0\u5f55\u5230\u78c1\u76d8\uff0c\u6027\u80fd\u8f83\u5dee\u4f46\u6570\u636e\u5b8c\u6574\u6027\u6bd4\u8f83\u597d<\/span><span>&nbsp;<\/span><\/span><\/li>\n<li><span>appendfsync&nbsp;everysec&nbsp;<span>\/\/\u9ed8\u8ba4\u63a8\u8350\uff0c\u5f02\u6b65\u64cd\u4f5c\uff0c\u6bcf\u79d2\u8bb0\u5f55\uff0c\u5982\u679c\u5b95\u673a\uff0c\u67091\u79d2\u5185\u6570\u636e\u4e22\u5931<\/span><span>&nbsp;<\/span><\/span><\/li>\n<li><span>appendfsync&nbsp;no&nbsp;<span>\/\/\u4e0d\u540c\u6b65\uff0c\u53ea\u6709\u5728\u64cd\u4f5c\u7cfb\u7edf\u9700\u8981\u65f6\u5728\u5237\u65b0\u6570\u636e<\/span><span>&nbsp;<\/span><\/span><\/li>\n<\/ol>\n<p>\u8981\u60f3\u4e86\u89e3\u63a5\u4e0b\u6765\u7684\u914d\u7f6e\u5185\u5bb9\uff0c\u5148\u5f97\u8bf4\u4e00\u4e0b\u201c\u65e5\u5fd7\u91cd\u5199\u201d\u7684\u539f\u7406\uff1a<\/p>\n<h4>\u91cd\u5199<\/h4>\n<p>\u7531\u4e8e&nbsp;<code>AOF<\/code>&nbsp;\u91c7\u7528\u7684\u662f\u5c06\u547d\u4ee4\u8ffd\u52a0\u5230\u6587\u4ef6\u672b\u5c3e\u7684\u65b9\u5f0f\uff0c\u6240\u4ee5\u968f\u7740\u5199\u5165\u547d\u4ee4\u7684\u4e0d\u65ad\u589e\u52a0\uff0c&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u4f53\u79ef\u4f1a\u53d8\u5f97\u8d8a\u6765\u8d8a\u5927\u3002\u4e3a\u907f\u514d\u51fa\u73b0\u6b64\u79cd\u60c5\u51b5\uff0c\u65b0\u589e\u4e86\u91cd\u5199\u673a\u5236\uff1a\u53ef\u4ee5\u5728\u4e0d\u6253\u65ad\u670d\u52a1\u5ba2\u6237\u7aef\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u8fdb\u884c\u91cd\u5efa\uff08&nbsp;<code>rebuild<\/code>&nbsp;\uff09\u3002<\/p>\n<p>\u91cd\u5199\u89e6\u53d1\uff1a\u901a\u8fc7\u6267\u884c&nbsp;<code>bgrewriteaof<\/code>&nbsp;\u547d\u4ee4\uff0c\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u65b0\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5305\u542b\u91cd\u5efa\u5f53\u524d\u6570\u636e\u96c6\u6240\u9700\u7684&nbsp;<strong>\u6700\u5c11<\/strong>&nbsp;\u547d\u4ee4\u3002&nbsp;<code>Redis 2.2<\/code>&nbsp;\u9700\u624b\u52a8\u6267\u884c\u8be5\u547d\u4ee4\uff0c&nbsp;<code>Redis 2.4<\/code>&nbsp;\u5219\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u7684\u65b9\u5f0f\u81ea\u52a8\u89e6\u53d1\uff08\u914d\u7f6e\u5728\u4e0b\u8fb9\u6d89\u53ca\uff09\u3002<\/p>\n<h4>\u91cd\u5199\u539f\u7406\uff1a<\/h4>\n<ul>\n<li><code>Redis<\/code>&nbsp;\u6267\u884c\u7cfb\u7edf\u51fd\u6570&nbsp;<code>fork()<\/code>&nbsp;\uff0c\u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff08\u4e0e\u4e3b\u8fdb\u7a0b\u5b8c\u5168\u4e00\u81f4\uff09\uff1b<\/li>\n<li>\u5b50\u8fdb\u7a0b\u5f00\u59cb\u5c06\u65b0&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u5185\u5bb9\u5199\u5165\u5230\u4e34\u65f6\u6587\u4ef6\uff1b<\/li>\n<li>\u5bf9\u4e8e\u6240\u6709\u65b0\u6267\u884c\u7684\u5199\u5165\u547d\u4ee4\uff0c\u7236\u8fdb\u7a0b\u4e00\u8fb9\u5c06\u5b83\u4eec\u7d2f\u79ef\u5230\u4e00\u4e2a\u5185\u5b58\u7f13\u5b58\u4e2d\uff0c\u4e00\u8fb9\u5c06\u8fd9\u4e9b\u6539\u52a8\u8ffd\u52a0\u5230\u73b0\u6709&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u672b\u5c3e\uff0c\u8fd9\u6837\u5373\u4f7f\u5728\u91cd\u5199\u7684\u4e2d\u9014\u53d1\u751f\u505c\u673a\uff0c\u73b0\u6709\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u4e5f\u662f\u5b89\u5168\u7684\uff1b<\/li>\n<li>\u5f53\u5b50\u8fdb\u7a0b\u5b8c\u6210\u91cd\u5199\u5de5\u4f5c\u65f6\uff0c\u5b83\u7ed9\u7236\u8fdb\u7a0b\u53d1\u9001\u4e00\u4e2a\u4fe1\u53f7\uff0c\u7236\u8fdb\u7a0b\u5728\u63a5\u6536\u5230\u4fe1\u53f7\u4e4b\u540e\uff0c\u5c06\u5185\u5b58\u7f13\u5b58\u4e2d\u7684\u6240\u6709\u6570\u636e\u8ffd\u52a0\u5230\u65b0&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u672b\u5c3e\u3002<\/li>\n<li><code>Redis<\/code>&nbsp;\u539f\u5b50\u5730\u7528\u65b0\u6587\u4ef6\u66ff\u6362\u65e7\u6587\u4ef6\uff0c\u4e4b\u540e\u6240\u6709\u547d\u4ee4\u90fd\u4f1a\u76f4\u63a5\u8ffd\u52a0\u5230\u65b0&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u672b\u5c3e\u3002<\/li>\n<\/ul>\n<h4>no-appendfsync-on-rewrite no<\/h4>\n<p>\u5f53\u6211\u4eec\u540c\u65f6\u6267\u884c\u4e3b\u8fdb\u7a0b\u7684&nbsp;<strong>\u5199\u64cd\u4f5c<\/strong>&nbsp;\u548c\u5b50\u8fdb\u7a0b\u7684&nbsp;<strong>\u91cd\u5199<\/strong>&nbsp;\u64cd\u4f5c\u65f6\uff0c\u4e24\u8005\u90fd\u4f1a\u64cd\u4f5c\u78c1\u76d8\uff0c\u800c\u91cd\u5199\u5f80\u5f80\u4f1a\u6d89\u53ca\u5230\u5927\u91cf\u7684\u78c1\u76d8\u64cd\u4f5c\uff0c\u8fd9\u6837\u5c31\u4f1a\u9020\u6210\u4e3b\u8fdb\u7a0b\u5728\u5199&nbsp;<code>aof<\/code>&nbsp;\u6587\u4ef6\u7684\u65f6\u5019\u51fa\u73b0\u963b\u585e\u7684\u60c5\u5f62\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c&nbsp;<code>no-appendfsync-on-rewrite<\/code>&nbsp;\u53c2\u6570\u51fa\u573a\u4e86\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u8be5\u53c2\u6570\u8bbe\u7f6e\u4e3a&nbsp;<code>no<\/code>&nbsp;\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\uff1b<\/li>\n<li>&nbsp;<\/li>\n<\/ul>\n<ol>\n<li><span><span>yes&nbsp;<\/span><\/span><\/li>\n<li><span>appendfsync&nbsp;<\/span><\/li>\n<li><span>no&nbsp;<\/span><\/li>\n<li><span>redis&nbsp;<\/span><\/li>\n<li><span>linux&nbsp;<\/span><\/li>\n<\/ol>\n<p>\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\u4e3a&nbsp;<code>yes<\/code>&nbsp;\uff1b\u5982\u679c\u5e94\u7528\u7cfb\u7edf\u65e0\u6cd5\u5fcd\u53d7\u6570\u636e\u4e22\u5931\uff0c\u5219\u8bbe\u7f6e\u4e3a&nbsp;<code>no<\/code>&nbsp;\u3002<\/p>\n<h4>auto-aof-rewrite-percentage 100<\/h4>\n<p>\u91cd\u5199\u767e\u5206\u6bd4\uff0c\u9ed8\u8ba4\u4e3a\u4e0a\u6b21\u91cd\u5199\u540e&nbsp;<code>aof<\/code>&nbsp;\u6587\u4ef6\u5927\u5c0f\u7684\u4e00\u500d\u3002<\/p>\n<h4>auto-aof-rewrite-min-size 64mb<\/h4>\n<p>\u91cd\u5199\u89e6\u53d1\u7684\u6700\u5c0f\u503c\uff1a64mb\u3002<\/p>\n<p>\u6839\u636e&nbsp;<code>auto-aof-rewrite-min-size<\/code>&nbsp;\u548c&nbsp;<code>auto-aof-rewrite-percentage<\/code>&nbsp;\u53c2\u6570\u786e\u5b9a\u81ea\u52a8\u89e6\u53d1\u65f6\u673a\u3002&nbsp;<code>Redis<\/code>&nbsp;\u4f1a\u8bb0\u5f55\u4e0a\u6b21\u91cd\u5199\u65f6\u7684&nbsp;<code>AOF<\/code>&nbsp;\u5927\u5c0f\uff0c\u9ed8\u8ba4\u914d\u7f6e\u662f\u5f53&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u5927\u5c0f\u662f\u4e0a\u6b21&nbsp;<code>rewrite<\/code>&nbsp;\u540e\u5927\u5c0f\u7684\u4e00\u500d\u4e14\u6587\u4ef6\u5927\u4e8e&nbsp;<code>64M<\/code>&nbsp;\u65f6\u89e6\u53d1\u3002<\/p>\n<p>\u5927\u578b\u4e92\u8054\u7f51\u516c\u53f8\u4e00\u822c\u90fd\u662f&nbsp;<code>3G<\/code>&nbsp;\u8d77\u6b65<\/p>\n<h4>aof-load-truncated yes<\/h4>\n<p>\u5f53&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u88ab\u622a\u65ad\u65f6\uff0c\u5373&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u6700\u540e\u547d\u4ee4\u4e0d\u5b8c\u6574\uff0c\u5982\u679c\u6b64\u65f6\u542f\u52a8&nbsp;<code>Redis<\/code>&nbsp;\uff0c\u4f1a\u5c06&nbsp;<code>AOF<\/code>&nbsp;\u6570\u636e\u52a0\u8f7d\u56de\u5185\u5b58\uff0c\u6b64\u65f6\u4fbf\u4f1a\u51fa\u73b0\u95ee\u9898\u3002<\/p>\n<ul>\n<li>yes\uff1a\u52a0\u8f7d\u4e00\u4e2a\u622a\u65ad\u7684&nbsp;<code>AOF<\/code>&nbsp;\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u670d\u52a1\u5668\u5f00\u59cb\u53d1\u51fa\u65e5\u5fd7\uff0c\u901a\u77e5\u7528\u6237\u8be5\u4e8b\u4ef6\uff1b<\/li>\n<li>\n<p>no\uff1a\u670d\u52a1\u5668\u5c06\u4e2d\u6b62\u5e76\u51fa\u73b0\u9519\u8bef\uff0c\u62d2\u7edd\u542f\u52a8\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5f53\u6211\u4eec\u5f97\u77e5&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u62a5\u9519\u65f6\uff0c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6765\u4fee\u590d\u51fa\u9519\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li>\n<p>\u4e3a\u73b0\u6709\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u521b\u5efa\u4e00\u4e2a\u5907\u4efd\uff1b<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528&nbsp;<code>Redis<\/code>&nbsp;\u9644\u5e26\u7684&nbsp;<code>redis-check-aof<\/code>&nbsp;\u547d\u4ee4\uff0c\u5bf9\u539f\u6765\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u8fdb\u884c\u4fee\u590d\uff1b<\/p>\n<ul>\n<li>\n<p><code>redis-check-aof \u2013fix<\/code><\/p>\n<\/li>\n<li>\n<p><code>redis-check-aof --fix appendonly.aof<\/code>&nbsp;\u4fee\u590d\u547d\u4ee4\uff0c\u6740\u5149\u4e0d\u7b26\u5408\u89c4\u8303\u7684\u8bed\u6cd5<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\uff08&nbsp;<strong>\u53ef\u9009<\/strong>&nbsp;\uff09\u4f7f\u7528&nbsp;<code>diff -u<\/code>&nbsp;\u5bf9\u6bd4\u4fee\u590d\u540e\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u548c\u539f\u59cb&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u5907\u4efd\uff0c\u67e5\u770b\u4e24\u4e2a\u6587\u4ef6\u4e4b\u95f4\u7684\u4e0d\u540c\u4e4b\u5904\uff1b<\/p>\n<\/li>\n<li>\n<p>\u91cd\u542f&nbsp;<code>Redis<\/code>&nbsp;\u670d\u52a1\u5668\uff0c\u7b49\u5f85\u670d\u52a1\u5668\u8f7d\u5165\u4fee\u590d\u540e\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\uff0c\u5e76\u8fdb\u884c\u6570\u636e\u6062\u590d\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>aof-use-rdb-preamble yes<\/h4>\n<p>\u5728\u91cd\u5199&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u65f6\uff0c&nbsp;<code>Redis<\/code>&nbsp;\u80fd\u591f\u5728&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u4e2d\u4f7f\u7528&nbsp;<code>RDB<\/code>&nbsp;\u524d\u5bfc\uff0c\u4ee5\u52a0\u5feb\u91cd\u5199\u548c\u6062\u590d\u901f\u5ea6\u3002\u542f\u7528\u6b64\u9009\u9879\u540e\uff0c\u91cd\u5199\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7531\u4e24\u4e2a\u4e0d\u540c\u7684\u8282\u7ec4\u6210\uff1a&nbsp;<code>RDB file<\/code>&nbsp;\u3001&nbsp;<code>AOF tail<\/code><\/p>\n<p>\u52a0\u8f7d&nbsp;<code>Redis<\/code>&nbsp;\u65f6\uff0c\u4f1a\u8bc6\u522b&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u4ee5&nbsp;<strong>Redis<\/strong>&nbsp;\u5b57\u7b26\u4e32\u5f00\u5934\uff0c\u5e76\u52a0\u8f7d\u5e26\u524d\u7f00\u7684&nbsp;<code>RDB<\/code>&nbsp;\u6587\u4ef6\uff0c\u7136\u540e\u7ee7\u7eed\u52a0\u8f7d&nbsp;<code>AOF<\/code>&nbsp;\u5c3e\u90e8\u3002<\/p>\n<h3>\u7406\u8bba<\/h3>\n<h4>\u4f18\u70b9<\/h4>\n<ul>\n<li>\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\u66f4\u9ad8\uff0c&nbsp;<code>AOF<\/code>&nbsp;\u7684\u6301\u4e45\u5316\u901a\u8fc7\u4f7f\u7528\u4e0d\u540c\u7684\u7b56\u7565\uff0c\u6700\u591a\u4e22\u59311\u79d2\u7684\u6570\u636e\uff1b<\/li>\n<li><code>AOF<\/code>&nbsp;\u6587\u4ef6\u662f\u4e00\u4e2a\u53ea\u8fdb\u884c\u8ffd\u52a0\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u4e0d\u9700\u8981\u5199\u5165&nbsp;<code>seek<\/code>&nbsp;\uff1b<\/li>\n<li>&nbsp;<\/li>\n<\/ul>\n<ol>\n<li><span><span>Redis&nbsp;<\/span><\/span><\/li>\n<li><span>AOF&nbsp;<\/span><\/li>\n<li><span>AOF&nbsp;<\/span><\/li>\n<\/ol>\n<li><code>AOF<\/code>&nbsp;\u6587\u4ef6\u8bb0\u5f55\u7684\u5199\u5165\u64cd\u4f5c\u4ee5&nbsp;<code>Redis<\/code>&nbsp;\u534f\u8bae\u7684\u683c\u5f0f\u4fdd\u5b58\uff0c\u5bb9\u6613\u8bfb\u61c2\uff0c\u5bb9\u6613\u5bf9\u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff1b<\/li>\n<h4>\u7f3a\u70b9<\/h4>\n<ul>\n<li>\u5bf9\u4e8e\u76f8\u540c\u7684\u6570\u636e\u96c6\u6765\u8bf4\uff0c&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u7684\u4f53\u79ef\u901a\u5e38\u8981\u5927\u4e8e&nbsp;<code>RDB<\/code>&nbsp;\u6587\u4ef6\u7684\u4f53\u79ef\uff1b<\/li>\n<li>&nbsp;<\/li>\n<\/ul>\n<ol>\n<li><span><span>fsync&nbsp;<\/span><\/span><\/li>\n<li><span>AOF&nbsp;<\/span><\/li>\n<li><span>RDB&nbsp;<\/span><\/li>\n<\/ol>\n<p>\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6bcf\u79d2&nbsp;<code>fsync<\/code>&nbsp;\u7684\u6027\u80fd\u4f9d\u7136\u975e\u5e38\u9ad8\uff0c\u800c\u5173\u95ed&nbsp;<code>fsync<\/code>&nbsp;\u53ef\u4ee5\u8ba9&nbsp;<code>AOF<\/code>&nbsp;\u7684\u901f\u5ea6\u548c&nbsp;<code>RDB<\/code>&nbsp;\u4e00\u6837\u5feb\uff0c \u5373\u4f7f\u5728\u9ad8\u8d1f\u8377\u4e4b\u4e0b\u4e5f\u662f\u5982\u6b64\u3002\u4e0d\u8fc7\u5728\u5904\u7406\u5de8\u5927\u7684\u5199\u5165\u8f7d\u5165\u65f6\uff0c&nbsp;<code>RDB<\/code>&nbsp;\u53ef\u4ee5\u63d0\u4f9b\u66f4\u6709\u4fdd\u8bc1\u7684\u6700\u5927\u5ef6\u8fdf\u65f6\u95f4\uff08&nbsp;<code>latency<\/code>&nbsp;\uff09\u3002<\/p>\n<h2>\u5bf9\u6bd4\u4e0e\u603b\u7ed3<\/h2>\n<h4>\u5982\u4f55\u9009\u62e9\u4f7f\u7528\u54ea\u79cd\u6301\u4e45\u5316\u65b9\u5f0f\uff1f<\/h4>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u5982\u679c\u60f3\u8fbe\u5230\u8db3\u4ee5\u5ab2\u7f8e&nbsp;<code>PostgreSQL<\/code>&nbsp;\u7684\u6570\u636e\u5b89\u5168\u6027\uff0c\u5e94\u8be5\u540c\u65f6\u4f7f\u7528\u4e24\u79cd\u6301\u4e45\u5316\u529f\u80fd\u3002<\/p>\n<p>\u5982\u679c\u975e\u5e38\u5173\u5fc3\u6570\u636e\uff0c\u4f46\u4ecd\u7136\u53ef\u4ee5\u627f\u53d7\u6570\u5206\u949f\u4ee5\u5185\u7684\u6570\u636e\u4e22\u5931\uff0c\u90a3\u4e48\u53ef\u4ee5\u53ea\u4f7f\u7528&nbsp;<code>RDB<\/code>&nbsp;\u6301\u4e45\u5316\u3002<\/p>\n<p>\u7531\u4e8eAOF\u6301\u4e45\u5316\u7684\u5b9e\u65f6\u6027\u66f4\u597d\uff0c\u5373\u5f53\u8fdb\u7a0b\u610f\u5916\u9000\u51fa\u65f6\u4e22\u5931\u7684\u6570\u636e\u66f4\u5c11\uff0c\u56e0\u6b64&nbsp;<code>AOF<\/code>&nbsp;\u662f\u76ee\u524d&nbsp;<strong>\u4e3b\u6d41<\/strong>&nbsp;\u7684\u6301\u4e45\u5316\u65b9\u5f0f\u3002<\/p>\n<p>\u6709\u5f88\u591a\u7528\u6237\u90fd\u53ea\u4f7f\u7528&nbsp;<code>AOF<\/code>&nbsp;\u6301\u4e45\u5316\uff0c\u4f46\u6211\u4eec\u5e76\u4e0d\u63a8\u8350\u8fd9\u79cd\u65b9\u5f0f\uff1a\u56e0\u4e3a\u5b9a\u65f6\u751f\u6210&nbsp;<code>RDB<\/code>&nbsp;\u5feb\u7167\uff08&nbsp;<code>snapshot<\/code>&nbsp;\uff09\u975e\u5e38\u4fbf\u4e8e\u8fdb\u884c\u6570\u636e\u5e93\u5907\u4efd\uff0c\u5e76\u4e14&nbsp;<code>RDB<\/code>&nbsp;\u6062\u590d\u6570\u636e\u96c6\u7684\u901f\u5ea6\u4e5f\u8981\u6bd4&nbsp;<code>AOF<\/code>&nbsp;\u6062\u590d\u7684\u901f\u5ea6\u8981\u5feb\u3002<\/p>\n<h4>AOF\u548cRDB\u4e4b\u95f4\u7684\u76f8\u4e92\u4f5c\u7528<\/h4>\n<p>\u5728\u7248\u672c\u53f7\u5927\u4e8e\u7b49\u4e8e&nbsp;<code>2.4<\/code>&nbsp;\u7684&nbsp;<code>Redis<\/code>&nbsp;\u4e2d\uff0c&nbsp;<code>BGSAVE<\/code>&nbsp;\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u53ef\u4ee5\u6267\u884c&nbsp;<code>BGREWRITEAOF<\/code>&nbsp;\u3002\u53cd\u8fc7\u6765\u8bf4\uff0c\u5728&nbsp;<code>BGREWRITEAOF<\/code>&nbsp;\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e5f\u4e0d\u53ef\u4ee5\u6267\u884c&nbsp;<code>BGSAVE<\/code>&nbsp;\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u4e24\u4e2a&nbsp;<code>Redis<\/code>&nbsp;\u540e\u53f0\u8fdb\u7a0b\u540c\u65f6\u5bf9\u78c1\u76d8\u8fdb\u884c\u5927\u91cf\u7684&nbsp;<code>I\/O<\/code>&nbsp;\u64cd\u4f5c\u3002<\/p>\n<p>\u5982\u679c&nbsp;<code>BGSAVE<\/code>&nbsp;\u6b63\u5728\u6267\u884c\uff0c\u5e76\u4e14\u7528\u6237\u663e\u793a\u5730\u8c03\u7528&nbsp;<code>BGREWRITEAOF<\/code>&nbsp;\u547d\u4ee4\uff0c\u90a3\u4e48\u670d\u52a1\u5668\u5c06\u5411\u7528\u6237\u56de\u590d\u4e00\u4e2a&nbsp;<code>OK<\/code>&nbsp;\u72b6\u6001\uff0c \u5e76\u544a\u77e5\u7528\u6237&nbsp;<code>BGREWRITEAOF<\/code>&nbsp;\u5df2\u7ecf\u88ab\u9884\u5b9a\u6267\u884c\uff1a\u4e00\u65e6&nbsp;<code>BGSAVE<\/code>&nbsp;\u6267\u884c\u5b8c\u6bd5\uff0c&nbsp;<code>BGREWRITEAOF<\/code>&nbsp;\u5c31\u4f1a\u6b63\u5f0f\u5f00\u59cb\u3002<\/p>\n<p>\u5f53&nbsp;<code>Redis<\/code>&nbsp;\u542f\u52a8\u65f6\uff0c\u5982\u679c&nbsp;<code>RDB<\/code>&nbsp;\u6301\u4e45\u5316\u548c&nbsp;<code>AOF<\/code>&nbsp;\u6301\u4e45\u5316\u90fd\u88ab\u6253\u5f00\u4e86\uff0c \u90a3\u4e48\u7a0b\u5e8f\u4f1a\u4f18\u5148\u4f7f\u7528&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u6765\u6062\u590d\u6570\u636e\u96c6\uff0c\u56e0\u4e3a&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u6240\u4fdd\u5b58\u7684\u6570\u636e\u901a\u5e38\u662f\u6700\u5b8c\u6574\u7684\u3002<\/p>\n<h4>\u5907\u4efdredis\u6570\u636e<\/h4>\n<ul>\n<li>&nbsp;<\/li>\n<\/ul>\n<ol>\n<li><span><span>cron&nbsp;job&nbsp;<\/span><\/span><\/li>\n<li><span>RDB&nbsp;<\/span><\/li>\n<li><span>RDB&nbsp;<\/span><\/li>\n<\/ol>\n<li>\u786e\u4fdd\u5feb\u7167\u7684\u5907\u4efd\u90fd\u5e26\u6709\u76f8\u5e94\u7684\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\uff0c\u6bcf\u6b21\u6267\u884c\u5b9a\u671f\u4efb\u52a1\u811a\u672c\u65f6\uff0c\u4f7f\u7528&nbsp;<code>find<\/code>&nbsp;\u547d\u4ee4\u6765\u5220\u9664\u8fc7\u671f\u7684\u5feb\u7167\uff1b<\/li>\n<li>\u81f3\u5c11\u6bcf\u5929\u4e00\u6b21\uff0c\u5c06&nbsp;<code>RDB<\/code>&nbsp;\u5907\u4efd\u5230\u4f60\u7684\u6570\u636e\u4e2d\u5fc3\u4e4b\u5916\uff0c\u6216\u8005\u81f3\u5c11\u662f\u5907\u4efd\u5230\u4f60\u8fd0\u884c&nbsp;<code>Redis<\/code>&nbsp;\u670d\u52a1\u5668\u7684\u7269\u7406\u673a\u5668\u4e4b\u5916\u3002<\/li>\n<h4>\u6027\u80fd\u5efa\u8bae<\/h4>\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u65f6\uff0c\u56e0\u4e3a&nbsp;<code>RDB<\/code>&nbsp;\u6587\u4ef6\u53ea\u7528\u4f5c\u540e\u5907\u7528\u9014\uff0c\u5efa\u8bae\u53ea\u5728&nbsp;<code>slave<\/code>&nbsp;\u4e0a\u6301\u4e45\u5316&nbsp;<code>RDB<\/code>&nbsp;\u6587\u4ef6\uff0c\u800c\u4e14\u53ea\u9700\u898115\u5206\u949f\u5907\u4efd\u4e00\u6b21\u5c31\u591f\u4e86\uff0c\u53ea\u4fdd\u7559&nbsp;<code>save 900 1<\/code>&nbsp;\u8fd9\u6761\u89c4\u5219\u3002<\/p>\n<p>\u5982\u679c\u5f00\u542f&nbsp;<code>AOF<\/code>&nbsp;\uff0c\u597d\u5904\u662f\u5728\u6700\u6076\u52a3\u60c5\u51b5\u4e0b\u4e5f\u53ea\u4f1a\u4e22\u5931\u4e0d\u8d85\u8fc72\u79d2\u6570\u636e\uff0c\u542f\u52a8\u811a\u672c\u8f83\u7b80\u5355\u53ea&nbsp;<code>load<\/code>&nbsp;\u81ea\u5df1\u7684&nbsp;<code>AOF<\/code>&nbsp;\u6587\u4ef6\u5c31\u53ef\u4ee5\u4e86\u3002\u4ee3\u4ef7\u4e00\u662f\u5e26\u6765\u4e86\u6301\u7eed\u7684&nbsp;<code>IO<\/code>&nbsp;\uff0c\u4e8c\u662f&nbsp;<code>AOF rewrite<\/code>&nbsp;\u7684\u6700\u540e\u5c06&nbsp;<code>rewrite<\/code>&nbsp;\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684\u65b0\u6570\u636e\u5199\u5230\u65b0\u6587\u4ef6\u9020\u6210\u7684\u963b\u585e\u51e0\u4e4e\u662f\u4e0d\u53ef\u907f\u514d\u7684\u3002<\/p>\n<p>\u53ea\u8981\u786c\u76d8\u8bb8\u53ef\uff0c\u5e94\u8be5\u5c3d\u91cf\u51cf\u5c11&nbsp;<code>AOF rewrite<\/code>&nbsp;\u7684\u9891\u7387\uff0c&nbsp;<code>AOF<\/code>&nbsp;\u91cd\u5199\u7684\u57fa\u7840\u5927\u5c0f\u9ed8\u8ba4\u503c&nbsp;<code>64M<\/code>&nbsp;\u592a\u5c0f\u4e86\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u5230&nbsp;<code>5G<\/code>&nbsp;\u4ee5\u4e0a\u3002\u9ed8\u8ba4\u8d85\u8fc7\u539f\u5927\u5c0f\u7684100%\u65f6\u91cd\u5199\u53ef\u4ee5\u6539\u5230\u9002\u5f53\u7684\u6570\u503c\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u5f00\u542f&nbsp;<code>AOF<\/code>&nbsp;\uff0c\u4ec5\u9760&nbsp;<code>Master-Slave Replication<\/code>&nbsp;\u5b9e\u73b0\u9ad8\u53ef\u7528\u6027\u4e5f\u53ef\u4ee5\u3002\u80fd\u7701\u6389\u4e00\u5927\u7b14&nbsp;<code>IO<\/code>&nbsp;\uff0c\u4e5f\u51cf\u5c11\u4e86&nbsp;<code>rewrite<\/code>&nbsp;\u65f6\u5e26\u6765\u7684\u7cfb\u7edf\u6ce2\u52a8\u3002\u4ee3\u4ef7\u662f\u5982\u679c&nbsp;<code>Master\/Slave<\/code>&nbsp;\u540c\u65f6\u5012\u6389\uff0c\u4f1a\u4e22\u5931\u5341\u51e0\u5206\u949f\u7684\u6570\u636e\uff0c\u542f\u52a8\u811a\u672c\u4e5f\u8981\u6bd4\u8f83\u4e24\u4e2a&nbsp;<code>Master\/Slave<\/code>&nbsp;\u4e2d\u7684&nbsp;<code>RDB<\/code>&nbsp;\u6587\u4ef6\uff0c\u8f7d\u5165\u8f83\u65b0\u7684\u90a3\u4e2a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u8bf4\u4f60\u7cbe\u901a Redis\uff0c\u4f60\u770b\u8fc7\u6301&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201479","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201479"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201479\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}