{"id":5828,"date":"2024-11-14T10:40:31","date_gmt":"2024-11-14T02:40:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5828\/"},"modified":"2024-11-14T10:40:31","modified_gmt":"2024-11-14T02:40:31","slug":"redis%e6%bb%a1%e5%86%85%e5%ad%98%e6%80%8e%e4%b9%88%e8%a7%a3%e9%99%a4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5828\/","title":{"rendered":"redis\u6ee1\u5185\u5b58\u600e\u4e48\u89e3\u9664"},"content":{"rendered":"<blockquote><p>\n  \u89e3\u51b3 redis \u6ee1\u5185\u5b58\u95ee\u9898\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u8bc6\u522b\u6ee1\u5185\u5b58\u539f\u56e0\uff1a\u5927\u578b\u6570\u636e\u96c6\u7f13\u6162\u5ba2\u6237\u7aef\u5185\u5b58\u6cc4\u6f0f\u914d\u7f6e\u9519\u8bef\u91c7\u53d6\u89e3\u51b3\u65b9\u6848\uff1a\u51cf\u5c11\u6570\u636e\u96c6\u4f18\u5316\u5ba2\u6237\u7aef\u6027\u80fd\u4fee\u590d\u5185\u5b58\u6cc4\u6f0f\u8c03\u6574 maxmemory \u914d\u7f6e\u907f\u514d\u7d27\u6025\u60c5\u51b5\uff1a\u542f\u7528 lru \u9010\u51fa\u7b56\u7565\u4f7f\u7528 aof \u6301\u4e45\u5316\u8bbe\u7f6e\u901a\u77e5\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060320185999018.jpg\" class=\"aligncenter\" title=\"redis\u6ee1\u5185\u5b58\u600e\u4e48\u89e3\u9664\u63d2\u56fe\" alt=\"redis\u6ee1\u5185\u5b58\u600e\u4e48\u89e3\u9664\u63d2\u56fe\" \/><\/p>\n<p><strong>Redis \u6ee1\u5185\u5b58\u7684\u89e3\u51b3\u529e\u6cd5<\/strong><\/p>\n<p>\u5f53 Redis \u5185\u5b58\u4f7f\u7528\u91cf\u8fbe\u5230\u6216\u8d85\u8fc7\u6700\u5927\u5185\u5b58\u9650\u5236\u65f6\uff0c\u5c31\u4f1a\u51fa\u73b0 Redis \u6ee1\u5185\u5b58\u7684\u60c5\u51b5\u3002\u6b64\u65f6\uff0cRedis \u4f1a\u505c\u6b62\u63a5\u6536\u65b0\u7684\u5199\u8bf7\u6c42\uff0c\u5e76\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef ERR out of memory \u9519\u8bef\u3002<\/p>\n<p><strong>1. \u8bc6\u522b\u6ee1\u5185\u5b58\u539f\u56e0<\/strong><\/p>\n<p>\u786e\u5b9a\u5bfc\u81f4 Redis \u6ee1\u5185\u5b58\u7684\u6839\u672c\u539f\u56e0\u81f3\u5173\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u539f\u56e0\uff1a<\/p>\n<ul>\n<li> <strong>\u5927\u578b\u6570\u636e\u96c6\uff1a<\/strong>Redis \u5b58\u50a8\u7684\u6570\u636e\u91cf\u8d85\u8fc7\u4e86\u53ef\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<li> <strong>\u7f13\u6162\u5ba2\u6237\u7aef\uff1a<\/strong>\u5ba2\u6237\u7aef\u5728\u5904\u7406 Redis \u8fd4\u56de\u7684\u6570\u636e\u65f6\u901f\u5ea6\u8f83\u6162\uff0c\u5bfc\u81f4 Redis \u7f13\u51b2\u533a\u4e2d\u7d2f\u79ef\u6570\u636e\u3002<\/li>\n<li> <strong>\u5185\u5b58\u6cc4\u6f0f\uff1a<\/strong>Redis \u4e2d\u5b58\u5728\u5185\u5b58\u9519\u8bef\u6216\u6cc4\u6f0f\uff0c\u5bfc\u81f4\u5185\u5b58\u88ab\u9519\u8bef\u5730\u5206\u914d\u6216\u4fdd\u7559\u3002<\/li>\n<li> <strong>\u914d\u7f6e\u9519\u8bef\uff1a<\/strong>maxmemory \u914d\u7f6e\u503c\u8bbe\u7f6e\u5f97\u592a\u4f4e\uff0c\u65e0\u6cd5\u5bb9\u7eb3\u6240\u9700\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><strong>2. \u91c7\u53d6\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u6839\u636e\u5bfc\u81f4\u6ee1\u5185\u5b58\u7684\u539f\u56e0\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<ul>\n<li> <strong>\u51cf\u5c11\u6570\u636e\u96c6\uff1a<\/strong>\u5220\u9664\u4e0d\u5fc5\u8981\u6216\u8fc7\u671f\u7684\u952e\uff0c\u6216\u8005\u5c06\u6570\u636e\u8fc1\u79fb\u5230\u5176\u4ed6\u6570\u636e\u5b58\u50a8\u4e2d\u3002<\/li>\n<li> <strong>\u4f18\u5316\u5ba2\u6237\u7aef\u6027\u80fd\uff1a<\/strong>\u6539\u8fdb\u5ba2\u6237\u7aef\u5904\u7406 Redis \u54cd\u5e94\u7684\u65b9\u5f0f\uff0c\u51cf\u5c11\u7f13\u51b2\u533a\u79ef\u538b\u3002<\/li>\n<li> <strong>\u4fee\u590d\u5185\u5b58\u6cc4\u6f0f\uff1a<\/strong>\u4f7f\u7528\u5185\u5b58\u8c03\u8bd5\u5de5\u5177\u6216\u5206\u6790 Redis \u65e5\u5fd7\u6765\u8bc6\u522b\u548c\u4fee\u590d\u4efb\u4f55\u5185\u5b58\u6cc4\u6f0f\u3002<\/li>\n<li> <strong>\u8c03\u6574 maxmemory \u914d\u7f6e\uff1a<\/strong>\u6839\u636e Redis \u4e2d\u6240\u9700\u7684\u6570\u636e\u91cf\uff0c\u9002\u5f53\u589e\u52a0 maxmemory \u914d\u7f6e\u503c\u3002<\/li>\n<\/ul>\n<p><strong>3. \u907f\u514d\u7d27\u6025\u60c5\u51b5<\/strong><\/p>\n<p>\u9664\u4e86\u4e0a\u8ff0\u63aa\u65bd\u5916\uff0c\u8fd8\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\u6765\u907f\u514d Redis \u6ee1\u5185\u5b58\u7684\u7d27\u6025\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li> <strong>\u542f\u7528 LRU \u9010\u51fa\u7b56\u7565\uff1a<\/strong>Redis \u9ed8\u8ba4\u4f7f\u7528 LRU (\u6700\u8fd1\u6700\u5c11\u4f7f\u7528) \u6dd8\u6c70\u7b56\u7565\uff0c\u5f53\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u81ea\u52a8\u9010\u51fa\u6700\u4e0d\u5e38\u7528\u7684\u952e\u3002<\/li>\n<li> <strong>\u4f7f\u7528 AOF \u6301\u4e45\u5316\uff1a<\/strong>\u542f\u7528 AOF (\u8ffd\u52a0\u4ec5\u9644\u52a0) \u6301\u4e45\u5316\uff0c\u5728\u53d1\u751f\u6ee1\u5185\u5b58\u9519\u8bef\u65f6\uff0cRedis \u53ef\u4ee5\u901a\u8fc7\u8fd8\u539f AOF \u6062\u590d\u6570\u636e\u3002<\/li>\n<li> <strong>\u8bbe\u7f6e\u901a\u77e5\uff1a<\/strong>\u914d\u7f6e Redis \u4ee5\u5728\u5185\u5b58\u4f7f\u7528\u91cf\u8fbe\u5230\u7279\u5b9a\u9608\u503c\u65f6\u53d1\u9001\u901a\u77e5\uff0c\u4ee5\u4fbf\u53ca\u65e9\u91c7\u53d6\u884c\u52a8\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6ee1\u5185\u5b58\u600e\u4e48\u89e3\u9664\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3 redis \u6ee1\u5185\u5b58\u95ee\u9898\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u8bc6\u522b\u6ee1\u5185\u5b58\u539f\u56e0\uff1a\u5927\u578b\u6570\u636e\u96c6\u7f13\u6162\u5ba2\u6237\u7aef\u5185\u5b58\u6cc4\u6f0f\u914d\u7f6e\u9519\u8bef\u91c7\u53d6\u89e3\u51b3\u65b9\u6848\uff1a\u51cf\u5c11\u6570\u636e\u96c6\u4f18\u5316\u5ba2\u6237\u7aef\u6027\u80fd\u4fee\u590d\u5185\u5b58\u6cc4\u6f0f\u8c03\u6574 maxmemory \u914d\u7f6e\u907f\u514d\u7d27\u6025\u60c5\u51b5\uff1a\u542f\u7528 lru \u9010\u51fa\u7b56\u7565\u4f7f\u7528 aof \u6301\u4e45\u5316\u8bbe\u7f6e\u901a\u77e5 Redis \u6ee1\u5185\u5b58\u7684\u89e3\u51b3\u529e\u6cd5 \u5f53 Redis \u5185\u5b58\u4f7f\u7528\u91cf\u8fbe\u5230\u6216\u8d85\u8fc7\u6700\u5927\u5185\u5b58\u9650\u5236\u65f6\uff0c\u5c31\u4f1a\u51fa\u73b0 Redis \u6ee1\u5185\u5b58\u7684\u60c5\u51b5\u3002\u6b64\u65f6\uff0cRedis \u4f1a\u505c\u6b62\u63a5\u6536\u65b0\u7684\u5199\u8bf7\u6c42\uff0c\u5e76\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef ERR out of memory \u9519\u8bef\u3002 1. \u8bc6\u522b\u6ee1\u5185\u5b58\u539f\u56e0 \u786e\u5b9a\u5bfc\u81f4 Redis \u6ee1\u5185\u5b58\u7684\u6839\u672c\u539f\u56e0\u81f3\u5173\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u539f\u56e0\uff1a \u5927\u578b\u6570\u636e\u96c6\uff1aRedis \u5b58\u50a8\u7684\u6570\u636e\u91cf\u8d85\u8fc7\u4e86\u53ef\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u3002 \u7f13\u6162\u5ba2\u6237\u7aef\uff1a\u5ba2\u6237\u7aef\u5728\u5904\u7406 Redis \u8fd4\u56de\u7684\u6570\u636e\u65f6\u901f\u5ea6\u8f83\u6162\uff0c\u5bfc\u81f4 Redis \u7f13\u51b2\u533a\u4e2d\u7d2f\u79ef\u6570\u636e\u3002 \u5185\u5b58\u6cc4\u6f0f\uff1aRedis \u4e2d\u5b58\u5728\u5185\u5b58\u9519\u8bef\u6216\u6cc4\u6f0f\uff0c\u5bfc\u81f4\u5185\u5b58\u88ab\u9519\u8bef\u5730\u5206\u914d\u6216\u4fdd\u7559\u3002 \u914d\u7f6e\u9519\u8bef\uff1amaxmemory \u914d\u7f6e\u503c\u8bbe\u7f6e\u5f97\u592a\u4f4e\uff0c\u65e0\u6cd5\u5bb9\u7eb3\u6240\u9700\u7684\u6570\u636e\u3002 2. \u91c7\u53d6\u89e3\u51b3\u65b9\u6848 \u6839\u636e\u5bfc\u81f4\u6ee1\u5185\u5b58\u7684\u539f\u56e0\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6848\uff1a \u51cf\u5c11\u6570\u636e\u96c6\uff1a\u5220\u9664\u4e0d\u5fc5\u8981\u6216\u8fc7\u671f\u7684\u952e\uff0c\u6216\u8005\u5c06\u6570\u636e\u8fc1\u79fb\u5230\u5176\u4ed6\u6570\u636e\u5b58\u50a8\u4e2d\u3002 \u4f18\u5316\u5ba2\u6237\u7aef\u6027\u80fd\uff1a\u6539\u8fdb\u5ba2\u6237\u7aef\u5904\u7406 Redis \u54cd\u5e94\u7684\u65b9\u5f0f\uff0c\u51cf\u5c11\u7f13\u51b2\u533a\u79ef\u538b\u3002 \u4fee\u590d\u5185\u5b58\u6cc4\u6f0f\uff1a\u4f7f\u7528\u5185\u5b58\u8c03\u8bd5\u5de5\u5177\u6216\u5206\u6790 Redis \u65e5\u5fd7\u6765\u8bc6\u522b\u548c\u4fee\u590d\u4efb\u4f55\u5185\u5b58\u6cc4\u6f0f\u3002 \u8c03\u6574 maxmemory \u914d\u7f6e\uff1a\u6839\u636e Redis \u4e2d\u6240\u9700\u7684\u6570\u636e\u91cf\uff0c\u9002\u5f53\u589e\u52a0 maxmemory \u914d\u7f6e\u503c\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5828","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5828"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5828\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}