{"id":6027,"date":"2024-11-14T13:25:51","date_gmt":"2024-11-14T05:25:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6027\/"},"modified":"2024-11-14T13:25:51","modified_gmt":"2024-11-14T05:25:51","slug":"redis%e8%bf%87%e6%9c%9f%e7%ad%96%e7%95%a5%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6027\/","title":{"rendered":"redis\u8fc7\u671f\u7b56\u7565\u5982\u4f55\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  redis \u8fc7\u671f\u7b56\u7565\u6709\u4e24\u79cd\uff1a\u5b9a\u671f\u5220\u9664\u548c\u60f0\u6027\u5220\u9664\u3002\u5b9a\u671f\u5220\u9664\u5728\u540e\u53f0\u4e3b\u52a8\u626b\u63cf\u6570\u636e\u5e93\uff0c\u7acb\u5373\u5220\u9664\u8fc7\u671f\u7684\u952e\u503c\u5bf9\uff0c\u8282\u7701\u5185\u5b58\u7a7a\u95f4\uff0c\u4f46\u53ef\u80fd\u5f71\u54cd\u6027\u80fd\u3002\u60f0\u6027\u5220\u9664\u53ea\u6709\u5728\u5ba2\u6237\u7aef\u8bbf\u95ee\u5df2\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u65f6\u624d\u4f1a\u5220\u9664\uff0c\u6027\u80fd\u5f00\u9500\u4f4e\uff0c\u4f46\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u53ef\u80fd\u7ee7\u7eed\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u3002\u5e94\u7528\u7a0b\u5e8f\u5e94\u6839\u636e\u9700\u6c42\u9009\u62e9\u7b56\u7565\uff0c\u5982\u9700\u8981\u7acb\u5373\u5220\u9664\u6216\u6027\u80fd\u4f18\u5148\u3002\u4f18\u5316\u63aa\u65bd\u5305\u62ec\u4f7f\u7528\u77ed ttl \u503c\u3001redis cluster \u5206\u5e03\u6570\u636e\u3001\u76d1\u63a7\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061216212187590.jpg\" class=\"aligncenter\" title=\"redis\u8fc7\u671f\u7b56\u7565\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" alt=\"redis\u8fc7\u671f\u7b56\u7565\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<h2>Redis \u8fc7\u671f\u7b56\u7565\u8bbe\u7f6e<\/h2>\n<p><strong>1. \u6982\u8ff0<\/strong><\/p>\n<p>Redis \u8fc7\u671f\u7b56\u7565\u5b9a\u4e49\u4e86\u5f53\u8fc7\u671f\u540e Redis \u5982\u4f55\u5904\u7406\u5b83\u4eec\u3002\u6709\u4e24\u79cd\u4e3b\u8981\u7b56\u7565\uff1a\u201c\u5b9a\u671f\u5220\u9664\u201d\u548c\u201c\u60f0\u6027\u5220\u9664\u201d\u3002<\/p>\n<p><strong>2. \u5b9a\u671f\u5220\u9664<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 <strong>expires<\/strong> \u547d\u4ee4\u8bbe\u7f6e\u952e\u503c\u5bf9\u7684\u751f\u5b58\u65f6\u95f4\uff08TTL\uff09\u3002<\/li>\n<li>Redis \u5728\u540e\u53f0\u5b9a\u671f\u626b\u63cf\u6570\u636e\u5e93\uff0c\u5220\u9664\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u3002<\/li>\n<li> <strong>\u4f18\u70b9\uff1a<\/strong> \u786e\u4fdd\u6240\u6709\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u53ca\u65f6\u5220\u9664\uff0c\u8282\u7701\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<li> <strong>\u7f3a\u70b9\uff1a<\/strong> \u626b\u63cf\u8fc7\u7a0b\u53ef\u80fd\u5f71\u54cd Redis \u6027\u80fd\uff0c\u5c24\u5176\u662f\u5f53\u6570\u636e\u5e93\u5f88\u5927\u65f6\u3002<\/li>\n<\/ul>\n<p><strong>3. \u60f0\u6027\u5220\u9664<\/strong><\/p>\n<ul>\n<li>\u5f53\u5ba2\u6237\u7aef\u5c1d\u8bd5\u8bbf\u95ee\u5df2\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u65f6\uff0cRedis \u624d\u4f1a\u5220\u9664\u5b83\u3002<\/li>\n<li>\u6b64\u7b56\u7565\u4e0d\u4f1a\u4e3b\u52a8\u626b\u63cf\u6570\u636e\u5e93\uff0c\u56e0\u6b64\u4e0d\u4f1a\u5f71\u54cd Redis \u6027\u80fd\u3002<\/li>\n<li> <strong>\u4f18\u70b9\uff1a<\/strong> \u6027\u80fd\u5f00\u9500\u4f4e\u3002<\/li>\n<li> <strong>\u7f3a\u70b9\uff1a<\/strong> \u8fc7\u671f\u7684\u952e\u503c\u5bf9\u53ef\u80fd\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u7ee7\u7eed\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<p><strong>4. \u8bbe\u7f6e\u65b9\u6cd5<\/strong><\/p>\n<p><strong>4.1 \u5b9a\u671f\u5220\u9664<\/strong><\/p>\n<pre>EXPIRE mykey 60  # \u8bbe\u7f6e mykey \u7684 TTL \u4e3a 60 \u79d2<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4.2 \u60f0\u6027\u5220\u9664<\/strong><\/p>\n<p>Redis \u9ed8\u8ba4\u4f7f\u7528\u60f0\u6027\u5220\u9664\u7b56\u7565\u3002\u53ef\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7981\u7528\u60f0\u6027\u5220\u9664\uff0c\u542f\u7528\u5b9a\u671f\u5220\u9664\uff1a<\/p>\n<pre>config set lazyfree-lazy-eviction no<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u9009\u62e9\u7b56\u7565<\/strong><\/p>\n<p>\u9009\u62e9\u54ea\u79cd\u7b56\u7565\u53d6\u51b3\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u5b9a\u9700\u6c42\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u9700\u8981\u7acb\u5373\u5220\u9664\u8fc7\u671f\u7684\u952e\u503c\u5bf9\uff0c\u5219\u9009\u62e9\u5b9a\u671f\u5220\u9664\u3002<\/li>\n<li>\u5982\u679c\u6027\u80fd\u662f\u4f18\u5148\u8003\u8651\u56e0\u7d20\uff0c\u5219\u9009\u62e9\u60f0\u6027\u5220\u9664\u3002<\/li>\n<\/ul>\n<p><strong>6. \u4f18\u5316<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u77ed TTL \u503c\u4ee5\u51cf\u5c11\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u6570\u91cf\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528 Redis Cluster\uff0c\u5b83\u53ef\u4ee5\u5c06\u6570\u636e\u5206\u5e03\u5728\u591a\u4e2a\u8282\u70b9\u4e0a\uff0c\u4ece\u800c\u51cf\u5c11\u5355\u4e2a\u8282\u70b9\u7684\u626b\u63cf\u8d1f\u62c5\u3002<\/li>\n<li>\u5b9a\u671f\u76d1\u89c6 Redis \u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5e76\u5728\u9700\u8981\u65f6\u8c03\u6574 TTL \u503c\u548c\u5220\u9664\u7b56\u7565\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fc7\u671f\u7b56\u7565\u5982\u4f55\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 \u8fc7\u671f\u7b56\u7565\u6709\u4e24\u79cd\uff1a\u5b9a\u671f\u5220\u9664\u548c\u60f0\u6027\u5220\u9664\u3002\u5b9a\u671f\u5220\u9664\u5728\u540e\u53f0\u4e3b\u52a8\u626b\u63cf\u6570\u636e\u5e93\uff0c\u7acb\u5373\u5220\u9664\u8fc7\u671f\u7684\u952e\u503c\u5bf9\uff0c\u8282\u7701\u5185\u5b58\u7a7a\u95f4\uff0c\u4f46\u53ef\u80fd\u5f71\u54cd\u6027\u80fd\u3002\u60f0\u6027\u5220\u9664\u53ea\u6709\u5728\u5ba2\u6237\u7aef\u8bbf\u95ee\u5df2\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u65f6\u624d\u4f1a\u5220\u9664\uff0c\u6027\u80fd\u5f00\u9500\u4f4e\uff0c\u4f46\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u53ef\u80fd\u7ee7\u7eed\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u3002\u5e94\u7528\u7a0b\u5e8f\u5e94\u6839\u636e\u9700\u6c42\u9009\u62e9\u7b56\u7565\uff0c\u5982\u9700\u8981\u7acb\u5373\u5220\u9664\u6216\u6027\u80fd\u4f18\u5148\u3002\u4f18\u5316\u63aa\u65bd\u5305\u62ec\u4f7f\u7528\u77ed ttl \u503c\u3001redis cluster \u5206\u5e03\u6570\u636e\u3001\u76d1\u63a7\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002 Redis \u8fc7\u671f\u7b56\u7565\u8bbe\u7f6e 1. \u6982\u8ff0 Redis \u8fc7\u671f\u7b56\u7565\u5b9a\u4e49\u4e86\u5f53\u8fc7\u671f\u540e Redis \u5982\u4f55\u5904\u7406\u5b83\u4eec\u3002\u6709\u4e24\u79cd\u4e3b\u8981\u7b56\u7565\uff1a\u201c\u5b9a\u671f\u5220\u9664\u201d\u548c\u201c\u60f0\u6027\u5220\u9664\u201d\u3002 2. \u5b9a\u671f\u5220\u9664 \u4f7f\u7528 expires \u547d\u4ee4\u8bbe\u7f6e\u952e\u503c\u5bf9\u7684\u751f\u5b58\u65f6\u95f4\uff08TTL\uff09\u3002 Redis \u5728\u540e\u53f0\u5b9a\u671f\u626b\u63cf\u6570\u636e\u5e93\uff0c\u5220\u9664\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u3002 \u4f18\u70b9\uff1a \u786e\u4fdd\u6240\u6709\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u53ca\u65f6\u5220\u9664\uff0c\u8282\u7701\u5185\u5b58\u7a7a\u95f4\u3002 \u7f3a\u70b9\uff1a \u626b\u63cf\u8fc7\u7a0b\u53ef\u80fd\u5f71\u54cd Redis \u6027\u80fd\uff0c\u5c24\u5176\u662f\u5f53\u6570\u636e\u5e93\u5f88\u5927\u65f6\u3002 3. \u60f0\u6027\u5220\u9664 \u5f53\u5ba2\u6237\u7aef\u5c1d\u8bd5\u8bbf\u95ee\u5df2\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u65f6\uff0cRedis \u624d\u4f1a\u5220\u9664\u5b83\u3002 \u6b64\u7b56\u7565\u4e0d\u4f1a\u4e3b\u52a8\u626b\u63cf\u6570\u636e\u5e93\uff0c\u56e0\u6b64\u4e0d\u4f1a\u5f71\u54cd Redis \u6027\u80fd\u3002 \u4f18\u70b9\uff1a \u6027\u80fd\u5f00\u9500\u4f4e\u3002 \u7f3a\u70b9\uff1a \u8fc7\u671f\u7684\u952e\u503c\u5bf9\u53ef\u80fd\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u7ee7\u7eed\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u3002 4. \u8bbe\u7f6e\u65b9\u6cd5 4.1 \u5b9a\u671f\u5220\u9664 EXPIRE mykey 60 # \u8bbe\u7f6e mykey \u7684 TTL \u4e3a 60 \u79d2 \u767b\u5f55\u540e\u590d\u5236 4.2 [&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-6027","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6027","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=6027"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6027\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}