{"id":871,"date":"2026-03-10T06:46:29","date_gmt":"2026-03-10T06:46:29","guid":{"rendered":"https:\/\/opshub.com.cn\/?p=871"},"modified":"2026-03-10T06:46:50","modified_gmt":"2026-03-10T06:46:50","slug":"redis-aof%e6%8c%81%e4%b9%85%e5%8c%96%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/opshub.com.cn\/?p=871","title":{"rendered":"Redis AOF\u6301\u4e45\u5316\u914d\u7f6e"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1. \u6838\u5fc3\u542b\u4e49\u4e0e\u4f5c\u7528<\/h3>\n\n\n\n<p><code>appendonly yes<\/code> \u7528\u4e8e\u5f00\u542f Redis \u7684 <strong>AOF\uff08Append Only File\uff09\u6301\u4e45\u5316\u6a21\u5f0f<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9ed8\u8ba4\u503c<\/strong>\uff1a<code>appendonly no<\/code>\uff08\u5173\u95ed AOF\uff0c\u9ed8\u8ba4\u4ec5\u5f00\u542f RDB\uff09<\/li>\n\n\n\n<li><strong>\u6838\u5fc3\u903b\u8f91<\/strong>\uff1a\u5f00\u542f\u540e\uff0cRedis \u4f1a\u5c06\u6bcf\u4e00\u6761\u5199\u547d\u4ee4\uff08\u5982 set\u3001hset\u3001incr \u7b49\uff09\u4ee5\u6587\u672c\u534f\u8bae\u7684\u5f62\u5f0f\u8ffd\u52a0\u5230 AOF \u6587\u4ef6\u4e2d\uff0c\u800c\u975e\u4ec5\u4f9d\u8d56 RDB \u7684\u5feb\u7167\u65b9\u5f0f\u3002<\/li>\n\n\n\n<li><strong>\u6838\u5fc3\u4ef7\u503c<\/strong>\uff1a\u76f8\u6bd4 RDB \u5feb\u7167\uff08\u53ef\u80fd\u4e22\u5931\u6700\u540e\u4e00\u6b21\u5feb\u7167\u540e\u7684\u6240\u6709\u6570\u636e\uff09\uff0cAOF \u80fd\u6700\u5927\u7a0b\u5ea6\u51cf\u5c11\u6570\u636e\u4e22\u5931\uff08\u53ef\u901a\u8fc7 <code>appendfsync<\/code> \u914d\u7f6e\u63a7\u5236\u4e22\u5931\u6570\u636e\u7684\u91cf\u7ea7\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5173\u952e\u914d\u5957\u914d\u7f6e\uff08\u5b8c\u6574\u793a\u4f8b\uff09<\/h3>\n\n\n\n<p>\u4ec5\u5f00\u542f <code>appendonly yes<\/code> \u8fd8\u4e0d\u591f\uff0c\u901a\u5e38\u9700\u8981\u642d\u914d\u4ee5\u4e0b\u914d\u7f6e\u624d\u80fd\u8fbe\u5230\u6700\u4f18\u6548\u679c\uff0c\u8fd9\u91cc\u7ed9\u51fa\u751f\u4ea7\u73af\u5883\u5e38\u7528\u7684\u5b8c\u6574\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5f00\u542fAOF\u6301\u4e45\u5316\nappendonly yes\n\n# AOF\u6587\u4ef6\u540d\u79f0\uff08\u9ed8\u8ba4\uff1aappendonly.aof\uff09\nappendfilename \"appendonly.aof\"\n\n# \u540c\u6b65\u7b56\u7565\uff08\u6838\u5fc3\uff0c\u51b3\u5b9a\u6570\u636e\u5b89\u5168\u6027\u4e0e\u6027\u80fd\u7684\u5e73\u8861\uff09\n# \u53ef\u9009\u503c\uff1a\n# - always\uff1a\u6bcf\u5199\u4e00\u6761\u547d\u4ee4\u5c31\u540c\u6b65\u5230\u78c1\u76d8\uff0c\u6570\u636e\u6700\u5b89\u5168\uff0c\u4f46\u6027\u80fd\u635f\u8017\u6700\u5927\n# - everysec\uff1a\u6bcf\u79d2\u540c\u6b65\u4e00\u6b21\uff08\u63a8\u8350\uff09\uff0c\u6700\u591a\u4e22\u59311\u79d2\u6570\u636e\uff0c\u6027\u80fd\u4e0e\u5b89\u5168\u517c\u987e\n# - no\uff1a\u7531\u64cd\u4f5c\u7cfb\u7edf\u51b3\u5b9a\u540c\u6b65\u65f6\u673a\uff0c\u6027\u80fd\u6700\u597d\uff0c\u4f46\u6570\u636e\u4e22\u5931\u98ce\u9669\u6700\u9ad8\nappendfsync everysec\n\n# \u5f00\u542fAOF\u91cd\u5199\u65f6\u662f\u5426\u4e34\u65f6\u5173\u95ed\u540c\u6b65\uff08\u907f\u514d\u91cd\u5199\u671f\u95f4\u6027\u80fd\u4e0b\u964d\uff09\nno-appendfsync-on-rewrite yes\n\n# AOF\u91cd\u5199\u89e6\u53d1\u6761\u4ef6\uff08\u907f\u514d\u6587\u4ef6\u8fc7\u5927\uff09\n# \u5f53\u524dAOF\u6587\u4ef6\u5927\u5c0f\u8d85\u8fc7\u4e0a\u4e00\u6b21\u91cd\u5199\u540e\u5927\u5c0f\u7684100%\uff0c\u4e14\u6587\u4ef6\u5927\u5c0f\u81f3\u5c1164MB\u65f6\u89e6\u53d1\u91cd\u5199\nauto-aof-rewrite-percentage 100\nauto-aof-rewrite-min-size 64mb\n\n# AOF\u6587\u4ef6\u635f\u574f\u65f6\u7684\u5904\u7406\u7b56\u7565\uff08yes\uff1a\u5ffd\u7565\u9519\u8bef\u7ee7\u7eed\u542f\u52a8\uff0cno\uff1a\u542f\u52a8\u5931\u8d25\uff09\naof-load-truncated yes<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u6838\u5fc3\u914d\u7f6e\u89e3\u91ca<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>appendfsync everysec<\/strong>\uff1a\u751f\u4ea7\u73af\u5883\u6700\u63a8\u8350\u7684\u914d\u7f6e\uff0c\u65e2\u4fdd\u8bc1\u4e86\u6027\u80fd\uff0c\u53c8\u5c06\u6570\u636e\u4e22\u5931\u63a7\u5236\u5728 1 \u79d2\u5185\uff1b<\/li>\n\n\n\n<li><strong>AOF \u91cd\u5199<\/strong>\uff1aAOF \u6587\u4ef6\u4f1a\u968f\u5199\u547d\u4ee4\u4e0d\u65ad\u589e\u5927\uff0c\u91cd\u5199\u4f1a\u5c06\u5197\u4f59\u547d\u4ee4\u5408\u5e76\uff08\u6bd4\u5982\u591a\u6b21 incr \u5408\u5e76\u4e3a set\uff09\uff0c\u51cf\u5c0f\u6587\u4ef6\u4f53\u79ef\uff0c\u4e14\u91cd\u5199\u8fc7\u7a0b\u662f\u5f02\u6b65\u7684\uff0c\u4e0d\u963b\u585e\u4e3b\u8fdb\u7a0b\uff1b<\/li>\n\n\n\n<li><strong>aof-load-truncated yes<\/strong>\uff1a\u5982\u679c AOF \u6587\u4ef6\u672b\u5c3e\u56e0\u5f02\u5e38\u635f\u574f\uff0cRedis \u4f1a\u5ffd\u7565\u635f\u574f\u90e8\u5206\u5e76\u6b63\u5e38\u542f\u52a8\uff0c\u907f\u514d\u56e0\u5c0f\u90e8\u5206\u635f\u574f\u5bfc\u81f4\u6574\u4e2a\u670d\u52a1\u65e0\u6cd5\u542f\u52a8\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u4f7f\u7528\u573a\u666f\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u9002\u7528\u573a\u666f<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u6570\u636e\u4e22\u5931\u654f\u611f\u7684\u4e1a\u52a1\uff08\u5982\u652f\u4ed8\u3001\u4ea4\u6613\u3001\u6838\u5fc3\u7f13\u5b58\uff09\uff1b<\/li>\n\n\n\n<li>\u8981\u6c42 \u201c\u5c3d\u53ef\u80fd\u5c11\u4e22\u6570\u636e\u201d\uff0c\u800c\u975e\u4ec5\u63a5\u53d7\u5feb\u7167\u7ea7\u522b\u7684\u6301\u4e45\u5316\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6027\u80fd\u5f71\u54cd<\/strong>\uff1aAOF \u4f1a\u6bd4\u7eaf RDB \u591a\u4e00\u4e9b\u78c1\u76d8 IO \u5f00\u9500\uff0c\u4f46 <code>everysec<\/code> \u6a21\u5f0f\u4e0b\u5f71\u54cd\u6781\u5c0f\uff0c\u53ef\u5ffd\u7565\uff1b<\/li>\n\n\n\n<li><strong>\u6587\u4ef6\u5927\u5c0f<\/strong>\uff1a\u5f00\u542f\u91cd\u5199\u914d\u7f6e\u540e\uff0c\u65e0\u9700\u62c5\u5fc3 AOF \u6587\u4ef6\u8fc7\u5927\uff0cRedis \u4f1a\u81ea\u52a8\u4f18\u5316\uff1b<\/li>\n\n\n\n<li><strong>\u517c\u5bb9 RDB<\/strong>\uff1aAOF \u548c RDB \u53ef\u540c\u65f6\u5f00\u542f\uff0cRedis \u91cd\u542f\u65f6\u4f1a\u4f18\u5148\u52a0\u8f7d AOF \u6587\u4ef6\uff08\u6570\u636e\u66f4\u5b8c\u6574\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>appendonly yes<\/code> \u6838\u5fc3\u4f5c\u7528\u662f\u5f00\u542f AOF \u6301\u4e45\u5316\uff0c\u5927\u5e45\u63d0\u5347\u6570\u636e\u53ef\u9760\u6027\uff0c\u51cf\u5c11\u4e22\u5931\u98ce\u9669\uff1b<\/li>\n\n\n\n<li>\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u642d\u914d <code>appendfsync everysec<\/code> \u4f7f\u7528\uff0c\u5e73\u8861\u6027\u80fd\u4e0e\u6570\u636e\u5b89\u5168\uff1b<\/li>\n\n\n\n<li>\u52a1\u5fc5\u5f00\u542f AOF \u91cd\u5199\u914d\u7f6e\uff0c\u907f\u514d\u6587\u4ef6\u4f53\u79ef\u65e0\u9650\u589e\u5927\u3002<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u6838\u5fc3\u542b\u4e49\u4e0e\u4f5c\u7528 appendonly yes \u7528\u4e8e\u5f00\u542f Redis \u7684 AOF\uff08Append Only File\uff09\u6301\u4e45\u5316\u6a21\u5f0f\uff1a 2. \u5173\u952e\u914d\u5957\u914d\u7f6e\uff08\u5b8c\u6574\u793a\u4f8b\uff09 \u4ec5\u5f00\u542f appendonly yes \u8fd8\u4e0d\u591f\uff0c\u901a\u5e38\u9700\u8981\u642d\u914d\u4ee5\u4e0b\u914d\u7f6e\u624d\u80fd\u8fbe\u5230\u6700\u4f18\u6548\u679c\uff0c\u8fd9\u91cc\u7ed9\u51fa\u751f\u4ea7\u73af\u5883\u5e38\u7528\u7684\u5b8c\u6574\u914d\u7f6e\u793a\u4f8b\uff1a 3. \u6838\u5fc3\u914d\u7f6e\u89e3\u91ca 4. \u4f7f\u7528\u573a\u666f\u4e0e\u6ce8\u610f\u4e8b\u9879 \u9002\u7528\u573a\u666f \u6ce8\u610f\u4e8b\u9879 \u603b\u7ed3<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-871","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=871"}],"version-history":[{"count":1,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions"}],"predecessor-version":[{"id":873,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions\/873"}],"wp:attachment":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}