{"id":5108,"date":"2024-11-14T13:04:03","date_gmt":"2024-11-14T05:04:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5108\/"},"modified":"2024-11-14T13:04:03","modified_gmt":"2024-11-14T05:04:03","slug":"redis%e8%bf%87%e6%9c%9f%e7%ad%96%e7%95%a5%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5108\/","title":{"rendered":"redis\u8fc7\u671f\u7b56\u7565\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  redis\u6570\u636e\u8fc7\u671f\u7b56\u7565\u6709\u4e24\u79cd\uff1a\u5b9a\u671f\u5220\u9664\uff1a\u5b9a\u671f\u626b\u63cf\u5220\u9664\u8fc7\u671f\u952e\uff0c\u53ef\u901a\u8fc7 expired-time-cap-remove-count\u3001expired-time-cap-remove-delay \u53c2\u6570\u8bbe\u7f6e\u3002\u60f0\u6027\u5220\u9664\uff1a\u4ec5\u5728\u8bfb\u53d6\u6216\u5199\u5165\u952e\u65f6\u68c0\u67e5\u5220\u9664\u8fc7\u671f\u952e\uff0c\u53ef\u901a\u8fc7 lazyfree-lazy-eviction\u3001lazyfree-lazy-expire\u3001lazyfree-lazy-user-del \u53c2\u6570\u8bbe\u7f6e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052116541874507.jpg\" class=\"aligncenter\" title=\"redis\u8fc7\u671f\u7b56\u7565\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"redis\u8fc7\u671f\u7b56\u7565\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>Redis \u8fc7\u671f\u7b56\u7565\u8bbe\u7f6e<\/strong><\/p>\n<p>Redis \u4e2d\u7684\u6570\u636e\u8fc7\u671f\u7b56\u7565\u4e3b\u8981\u6709\u4e24\u79cd\uff1a<\/p>\n<ul>\n<li> <strong>\u5b9a\u671f\u5220\u9664 (cron)\uff1a<\/strong>\u7cfb\u7edf\u5b9a\u671f\u626b\u63cf\u6240\u6709\u952e\uff0c\u5e76\u5220\u9664\u8fc7\u671f\u7684\u952e\u3002<\/li>\n<li> <strong>\u60f0\u6027\u5220\u9664\uff1a<\/strong>\u4ec5\u5728\u8bfb\u53d6\u6216\u5199\u5165\u952e\u65f6\uff0c\u624d\u4f1a\u68c0\u67e5\u5e76\u5220\u9664\u8fc7\u671f\u7684\u952e\u3002<\/li>\n<\/ul>\n<p><strong>\u8fc7\u671f\u7b56\u7565\u8bbe\u7f6e<\/strong><\/p>\n<p><strong>1. \u5b9a\u671f\u5220\u9664<\/strong><\/p>\n<pre>CONFIG SET expired-time-cap-remove-count 100000 # \u6bcf\u6b21\u626b\u63cf\u5220\u9664\u7684\u6700\u5927\u952e\u6570\u91cf\nCONFIG SET expired-time-cap-remove-delay 5 # \u5220\u9664\u64cd\u4f5c\u7684\u5ef6\u8fdf\u65f6\u95f4\uff08\u79d2\uff09<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u60f0\u6027\u5220\u9664<\/strong><\/p>\n<pre>CONFIG SET lazyfree-lazy-eviction true # \u542f\u7528\u60f0\u6027\u5220\u9664\nCONFIG SET lazyfree-lazy-expire false # \u5931\u6548\u540e\u7acb\u5373\u5f00\u59cb\u5220\u9664\u64cd\u4f5c\nCONFIG SET lazyfree-lazy-user-del true # \u901a\u8fc7 DEL \u547d\u4ee4\u5220\u9664\u7684\u952e\u7acb\u5373\u5220\u9664<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u53c2\u6570\u8bf4\u660e<\/strong><\/p>\n<ul>\n<li> <strong>expired-time-cap-remove-count:<\/strong> \u6bcf\u6b21\u626b\u63cf\u5220\u9664\u7684\u6700\u5927\u952e\u6570\u91cf\u3002<\/li>\n<li> <strong>expired-time-cap-remove-delay:<\/strong> \u5220\u9664\u64cd\u4f5c\u7684\u5ef6\u8fdf\u65f6\u95f4\uff0c\u4ee5\u51cf\u5c11\u670d\u52a1\u5668\u8d1f\u8f7d\u3002<\/li>\n<li> <strong>lazyfree-lazy-eviction:<\/strong> \u542f\u7528\u60f0\u6027\u5220\u9664\u3002<\/li>\n<li> <strong>lazyfree-lazy-expire:<\/strong> \u5931\u6548\u540e\u7acb\u5373\u5f00\u59cb\u5220\u9664\u64cd\u4f5c\u3002<\/li>\n<li> <strong>lazyfree-lazy-user-del:<\/strong> \u901a\u8fc7 DEL \u547d\u4ee4\u5220\u9664\u7684\u952e\u7acb\u5373\u5220\u9664\u3002<\/li>\n<\/ul>\n<p><strong>\u9009\u62e9\u7b56\u7565<\/strong><\/p>\n<p>\u5b9a\u671f\u5220\u9664\u7b56\u7565\u9002\u7528\u4e8e\u6570\u636e\u91cf\u5927\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u5b9a\u671f\u5220\u9664\u8fc7\u671f\u952e\uff0c\u907f\u514d\u5185\u5b58\u6d6a\u8d39\u3002\u60f0\u6027\u5220\u9664\u7b56\u7565\u9002\u7528\u4e8e\u6570\u636e\u91cf\u8f83\u5c0f\u6216\u5bf9\u6027\u80fd\u8981\u6c42\u8f83\u9ad8\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u51cf\u5c11\u670d\u52a1\u5668\u626b\u63cf\u548c\u5220\u9664\u64cd\u4f5c\u7684\u5f00\u9500\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fc7\u671f\u7b56\u7565\u600e\u4e48\u8bbe\u7f6e\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>redis\u6570\u636e\u8fc7\u671f\u7b56\u7565\u6709\u4e24\u79cd\uff1a\u5b9a\u671f\u5220\u9664\uff1a\u5b9a\u671f\u626b\u63cf\u5220\u9664\u8fc7\u671f\u952e\uff0c\u53ef\u901a\u8fc7 expired-time-cap-remove-count\u3001expired-time-cap-remove-delay \u53c2\u6570\u8bbe\u7f6e\u3002\u60f0\u6027\u5220\u9664\uff1a\u4ec5\u5728\u8bfb\u53d6\u6216\u5199\u5165\u952e\u65f6\u68c0\u67e5\u5220\u9664\u8fc7\u671f\u952e\uff0c\u53ef\u901a\u8fc7 lazyfree-lazy-eviction\u3001lazyfree-lazy-expire\u3001lazyfree-lazy-user-del \u53c2\u6570\u8bbe\u7f6e\u3002 Redis \u8fc7\u671f\u7b56\u7565\u8bbe\u7f6e Redis \u4e2d\u7684\u6570\u636e\u8fc7\u671f\u7b56\u7565\u4e3b\u8981\u6709\u4e24\u79cd\uff1a \u5b9a\u671f\u5220\u9664 (cron)\uff1a\u7cfb\u7edf\u5b9a\u671f\u626b\u63cf\u6240\u6709\u952e\uff0c\u5e76\u5220\u9664\u8fc7\u671f\u7684\u952e\u3002 \u60f0\u6027\u5220\u9664\uff1a\u4ec5\u5728\u8bfb\u53d6\u6216\u5199\u5165\u952e\u65f6\uff0c\u624d\u4f1a\u68c0\u67e5\u5e76\u5220\u9664\u8fc7\u671f\u7684\u952e\u3002 \u8fc7\u671f\u7b56\u7565\u8bbe\u7f6e 1. \u5b9a\u671f\u5220\u9664 CONFIG SET expired-time-cap-remove-count 100000 # \u6bcf\u6b21\u626b\u63cf\u5220\u9664\u7684\u6700\u5927\u952e\u6570\u91cf CONFIG SET expired-time-cap-remove-delay 5 # \u5220\u9664\u64cd\u4f5c\u7684\u5ef6\u8fdf\u65f6\u95f4\uff08\u79d2\uff09 \u767b\u5f55\u540e\u590d\u5236 2. \u60f0\u6027\u5220\u9664 CONFIG SET lazyfree-lazy-eviction true # \u542f\u7528\u60f0\u6027\u5220\u9664 CONFIG SET lazyfree-lazy-expire false # \u5931\u6548\u540e\u7acb\u5373\u5f00\u59cb\u5220\u9664\u64cd\u4f5c CONFIG SET lazyfree-lazy-user-del true # \u901a\u8fc7 DEL \u547d\u4ee4\u5220\u9664\u7684\u952e\u7acb\u5373\u5220\u9664 \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570\u8bf4\u660e expired-time-cap-remove-count: \u6bcf\u6b21\u626b\u63cf\u5220\u9664\u7684\u6700\u5927\u952e\u6570\u91cf\u3002 expired-time-cap-remove-delay: [&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-5108","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5108","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=5108"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5108\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}