{"id":120922,"date":"2024-10-25T10:34:18","date_gmt":"2024-10-25T02:34:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/120922\/"},"modified":"2024-10-25T10:34:19","modified_gmt":"2024-10-25T02:34:19","slug":"redis-%e5%bf%ab%e5%8f%96%e8%87%aa%e5%8b%95%e6%b8%85%e7%90%86%e7%ad%96%e7%95%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/120922\/","title":{"rendered":"Redis \u5feb\u53d6\u81ea\u52d5\u6e05\u7406\u7b56\u7565"},"content":{"rendered":"<h1 id=\"redis-%e5%bf%ab%e5%8f%96%e8%87%aa%e5%8b%95%e6%b8%85%e7%90%86%e7%ad%96%e7%95%a5-bVpFtnDlJe\">Redis \u5feb\u53d6\u81ea\u52d5\u6e05\u7406\u7b56\u7565<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u8def\u61c9\u7528\u4e2d\uff0c\u5feb\u53d6\u6280\u8853\u5df2\u6210\u70ba\u63d0\u5347\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u7684\u91cd\u8981\u624b\u6bb5\u3002Redis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u8a18\u61b6\u9ad4\u8cc7\u6599\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5feb\u53d6\u7cfb\u7d71\u4e2d\u3002\u7136\u800c\uff0c\u96a8\u8457\u8cc7\u6599\u7684\u589e\u9577\uff0c\u5982\u4f55\u6709\u6548\u7ba1\u7406\u5feb\u53d6\u8cc7\u6599\uff0c\u7279\u5225\u662f\u81ea\u52d5\u6e05\u7406\u904e\u671f\u8cc7\u6599\uff0c\u6210\u70ba\u4e86\u958b\u767c\u8005\u9700\u8981\u9762\u5c0d\u7684\u6311\u6230\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Redis \u7684\u5feb\u53d6\u81ea\u52d5\u6e05\u7406\u7b56\u7565\uff0c\u5305\u62ec\u5176\u5de5\u4f5c\u539f\u7406\u3001\u914d\u7f6e\u9078\u9805\u53ca\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2 id=\"redis-%e7%9a%84%e5%bf%ab%e5%8f%96%e6%a9%9f%e5%88%b6-bVpFtnDlJe\">Redis \u7684\u5feb\u53d6\u6a5f\u5236<\/h2>\n<p>Redis \u4e3b\u8981\u901a\u904e\u5c07\u8cc7\u6599\u5b58\u5132\u5728\u8a18\u61b6\u9ad4\u4e2d\u4f86\u5be6\u73fe\u5feb\u901f\u8b80\u53d6\u3002\u9019\u4f7f\u5f97 Redis \u6210\u70ba\u4e00\u500b\u7406\u60f3\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\u3002\u7576\u8cc7\u6599\u88ab\u5beb\u5165 Redis \u6642\uff0c\u53ef\u4ee5\u8a2d\u7f6e\u904e\u671f\u6642\u9593\uff0c\u9019\u6a23\u8cc7\u6599\u5728\u9054\u5230\u6307\u5b9a\u6642\u9593\u5f8c\u6703\u81ea\u52d5\u88ab\u6e05\u9664\u3002\u9019\u4e00\u904e\u7a0b\u7a31\u70ba\u300c\u81ea\u52d5\u6e05\u7406\u300d\u3002<\/p>\n<h2 id=\"%e8%87%aa%e5%8b%95%e6%b8%85%e7%90%86%e7%ad%96%e7%95%a5-bVpFtnDlJe\">\u81ea\u52d5\u6e05\u7406\u7b56\u7565<\/h2>\n<p>Redis \u63d0\u4f9b\u4e86\u5169\u7a2e\u4e3b\u8981\u7684\u81ea\u52d5\u6e05\u7406\u7b56\u7565\uff1a<\/p>\n<ul>\n<li><strong>\u5b9a\u671f\u6e05\u7406\uff08Active Expiration\uff09<\/strong>\uff1aRedis \u6703\u5b9a\u671f\u6aa2\u67e5\u5feb\u53d6\u4e2d\u7684\u8cc7\u6599\uff0c\u4e26\u522a\u9664\u90a3\u4e9b\u5df2\u904e\u671f\u7684\u9805\u76ee\u3002\u9019\u500b\u904e\u7a0b\u901a\u5e38\u5728\u6bcf\u79d2\u9032\u884c\u4e00\u6b21\uff0c\u5177\u9ad4\u7684\u904e\u671f\u6aa2\u67e5\u6578\u91cf\u53ef\u4ee5\u901a\u904e\u914d\u7f6e\u53c3\u6578\u9032\u884c\u8abf\u6574\u3002<\/li>\n<li><strong>\u60f0\u6027\u6e05\u7406\uff08Lazy Expiration\uff09<\/strong>\uff1a\u7576\u5ba2\u6236\u7aef\u8acb\u6c42\u67d0\u500b\u8cc7\u6599\u6642\uff0cRedis \u6703\u6aa2\u67e5\u8a72\u8cc7\u6599\u662f\u5426\u5df2\u904e\u671f\u3002\u5982\u679c\u5df2\u904e\u671f\uff0c\u5247\u6703\u7acb\u5373\u522a\u9664\u8a72\u8cc7\u6599\u4e26\u8fd4\u56de\u7a7a\u503c\u3002\u9019\u7a2e\u65b9\u5f0f\u4e0d\u6703\u4e3b\u52d5\u6e05\u7406\u8cc7\u6599\uff0c\u4f46\u80fd\u5920\u5728\u8cc7\u6599\u88ab\u8a2a\u554f\u6642\u9032\u884c\u6e05\u7406\u3002<\/li>\n<\/ul>\n<h2 id=\"%e9%85%8d%e7%bd%ae%e9%81%b8%e9%a0%85-bVpFtnDlJe\">\u914d\u7f6e\u9078\u9805<\/h2>\n<p>Redis \u63d0\u4f9b\u4e86\u4e00\u4e9b\u914d\u7f6e\u9078\u9805\u4f86\u8abf\u6574\u81ea\u52d5\u6e05\u7406\u7684\u884c\u70ba\uff1a<\/p>\n<ul>\n<li><strong>maxmemory<\/strong>\uff1a\u9019\u500b\u53c3\u6578\u7528\u4f86\u8a2d\u7f6e Redis \u7684\u6700\u5927\u8a18\u61b6\u9ad4\u4f7f\u7528\u91cf\u3002\u4e00\u65e6\u9054\u5230\u9019\u500b\u9650\u5236\uff0cRedis \u5c07\u6839\u64da\u914d\u7f6e\u7684\u6e05\u7406\u7b56\u7565\u4f86\u522a\u9664\u8cc7\u6599\u3002<\/li>\n<li><strong>maxmemory-policy<\/strong>\uff1a\u9019\u500b\u53c3\u6578\u7528\u4f86\u8a2d\u7f6e\u7576\u8a18\u61b6\u9ad4\u9054\u5230\u4e0a\u9650\u6642\u7684\u6e05\u7406\u7b56\u7565\u3002\u53ef\u9078\u7684\u7b56\u7565\u5305\u62ec\uff1a<\/li>\n<ul>\n<li><code>noeviction<\/code>\uff1a\u4e0d\u6703\u522a\u9664\u4efb\u4f55\u8cc7\u6599\uff0c\u76f4\u63a5\u8fd4\u56de\u932f\u8aa4\u3002<\/li>\n<li><code>allkeys-lru<\/code>\uff1a\u4f7f\u7528 LRU\uff08Least Recently Used\uff09\u7b97\u6cd5\u522a\u9664\u6700\u5c11\u4f7f\u7528\u7684\u8cc7\u6599\u3002<\/li>\n<li><code>volatile-lru<\/code>\uff1a\u50c5\u522a\u9664\u8a2d\u7f6e\u4e86\u904e\u671f\u6642\u9593\u7684\u8cc7\u6599\u3002<\/li>\n<li><code>allkeys-random<\/code>\uff1a\u96a8\u6a5f\u522a\u9664\u8cc7\u6599\u3002<\/li>\n<li><code>volatile-random<\/code>\uff1a\u96a8\u6a5f\u522a\u9664\u8a2d\u7f6e\u4e86\u904e\u671f\u6642\u9593\u7684\u8cc7\u6599\u3002<\/li>\n<\/ul>\n<\/ul>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-bVpFtnDlJe\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u4f7f\u7528 Redis \u9032\u884c\u5feb\u53d6\u6642\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\uff1a<\/p>\n<ul>\n<li>\u6839\u64da\u61c9\u7528\u9700\u6c42\u5408\u7406\u8a2d\u7f6e\u904e\u671f\u6642\u9593\uff0c\u907f\u514d\u8cc7\u6599\u904e\u671f\u5f8c\u4ecd\u7136\u4f54\u7528\u8a18\u61b6\u9ad4\u3002<\/li>\n<li>\u5b9a\u671f\u76e3\u63a7 Redis \u7684\u8a18\u61b6\u9ad4\u4f7f\u7528\u60c5\u6cc1\uff0c\u53ca\u6642\u8abf\u6574 <code>maxmemory<\/code> \u548c <code>maxmemory-policy<\/code> \u7684\u914d\u7f6e\u3002<\/li>\n<li>\u4f7f\u7528 Redis \u7684 <code>INFO<\/code> \u547d\u4ee4\u4f86\u6aa2\u67e5\u5feb\u53d6\u7684\u72c0\u614b\uff0c\u4e86\u89e3\u904e\u671f\u8cc7\u6599\u7684\u6578\u91cf\u548c\u6e05\u7406\u60c5\u6cc1\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-bVpFtnDlJe\">\u7d50\u8ad6<\/h2>\n<p>Redis \u7684\u5feb\u53d6\u81ea\u52d5\u6e05\u7406\u7b56\u7565\u662f\u5176\u9ad8\u6548\u6027\u80fd\u7684\u91cd\u8981\u7d44\u6210\u90e8\u5206\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e\u548c\u7ba1\u7406\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u78ba\u4fdd\u7cfb\u7d71\u5728\u9ad8\u8ca0\u8f09\u4e0b\u4ecd\u80fd\u4fdd\u6301\u7a69\u5b9a\u6027\u548c\u5feb\u901f\u97ff\u61c9\u3002\u4e86\u89e3\u9019\u4e9b\u7b56\u7565\u4e0d\u50c5\u80fd\u5e6b\u52a9\u958b\u767c\u8005\u512a\u5316\u61c9\u7528\u6027\u80fd\uff0c\u9084\u80fd\u6709\u6548\u964d\u4f4e\u8cc7\u6e90\u6d6a\u8cbb\u3002<\/p>\n<p>\u5982\u9700\u9032\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u5728\u60a8\u7684\u61c9\u7528\u4e2d\u5be6\u65bd Redis \u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u60a8\u53ef\u4ee5\u53c3\u8003\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\uff0c\u63d0\u4f9b\u7a69\u5b9a\u7684\u74b0\u5883\u4ee5\u652f\u6301\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Redis \u5feb\u53d6\u81ea\u52d5\u6e05\u7406\u7b56\u7565\uff0c\u4e86\u89e3\u5982\u4f55\u6709\u6548\u7ba1\u7406\u5feb\u53d6\u6578\u64da\uff0c\u63d0\u5347\u6027\u80fd\u8207\u8cc7\u6e90\u5229\u7528\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-120922","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/120922","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=120922"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/120922\/revisions"}],"predecessor-version":[{"id":120923,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/120922\/revisions\/120923"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=120922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=120922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=120922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}