{"id":180586,"date":"2024-11-09T11:30:16","date_gmt":"2024-11-09T03:30:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/180586\/"},"modified":"2024-11-09T11:30:16","modified_gmt":"2024-11-09T03:30:16","slug":"%e6%b7%b1%e5%85%a5%e8%a7%a3%e8%ae%80redis%e4%b8%ad%e4%ba%94%e5%80%8b%e9%87%8d%e8%a6%81%e5%8f%83%e6%95%b8%e5%90%ab%e7%be%a9%ef%bc%88%e4%ba%94%e5%80%8bredis%e5%8f%83%e6%95%b8%e7%9a%84%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/180586\/","title":{"rendered":"\u6df1\u5165\u89e3\u8b80Redis\u4e2d\u4e94\u500b\u91cd\u8981\u53c3\u6578\u542b\u7fa9\uff08\u4e94\u500bredis\u53c3\u6578\u7684\u610f\u601d\uff09"},"content":{"rendered":"<h1 id=\"%e6%b7%b1%e5%85%a5%e8%a7%a3%e8%ae%80redis%e4%b8%ad%e4%ba%94%e5%80%8b%e9%87%8d%e8%a6%81%e5%8f%83%e6%95%b8%e5%90%ab%e7%be%a9-WCxrpRRiLc\">\u6df1\u5165\u89e3\u8b80Redis\u4e2d\u4e94\u500b\u91cd\u8981\u53c3\u6578\u542b\u7fa9<\/h1>\n<p>Redis\u662f\u4e00\u500b\u9ad8\u6548\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u5be6\u6642\u6578\u64da\u5206\u6790\u7b49\u5834\u666f\u3002\u4e86\u89e3Redis\u7684\u914d\u7f6e\u53c3\u6578\u5c0d\u65bc\u512a\u5316\u5176\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u4e94\u500b\u91cd\u8981\u7684Redis\u53c3\u6578\u53ca\u5176\u542b\u7fa9\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u914d\u7f6e\u548c\u4f7f\u7528Redis\u3002<\/p>\n<h2 id=\"1-maxmemory-WCxrpRRiLc\">1. maxmemory<\/h2>\n<p>\u53c3\u6578 <code>maxmemory<\/code> \u7528\u65bc\u8a2d\u5b9aRedis\u53ef\u4ee5\u4f7f\u7528\u7684\u6700\u5927\u5167\u5b58\u91cf\u3002\u7576Redis\u7684\u5167\u5b58\u4f7f\u7528\u91cf\u9054\u5230\u9019\u500b\u9650\u5236\u6642\uff0c\u5c07\u6839\u64da\u914d\u7f6e\u7684\u9a45\u9010\u7b56\u7565\u4f86\u522a\u9664\u820a\u7684\u6578\u64da\u3002\u9019\u500b\u53c3\u6578\u7684\u8a2d\u7f6e\u5c0d\u65bc\u9632\u6b62\u5167\u5b58\u6ea2\u51fa\u81f3\u95dc\u91cd\u8981\uff0c\u7279\u5225\u662f\u5728\u9ad8\u8ca0\u8f09\u7684\u74b0\u5883\u4e2d\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u5c07\u6700\u5927\u5167\u5b58\u8a2d\u7f6e\u70ba512MB\uff0c\u53ef\u4ee5\u5728Redis\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>maxmemory 512mb<\/code><\/pre>\n<h2 id=\"2-maxmemory-policy-WCxrpRRiLc\">2. maxmemory-policy<\/h2>\n<p>\u53c3\u6578 <code>maxmemory-policy<\/code> \u5b9a\u7fa9\u4e86\u7576Redis\u9054\u5230 <code>maxmemory<\/code> \u9650\u5236\u6642\uff0c\u61c9\u8a72\u5982\u4f55\u8655\u7406\u65b0\u9032\u4f86\u7684\u6578\u64da\u3002Redis\u63d0\u4f9b\u4e86\u591a\u7a2e\u9a45\u9010\u7b56\u7565\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>noeviction<\/code>: \u4e0d\u9a45\u9010\u4efb\u4f55\u6578\u64da\uff0c\u7576\u5167\u5b58\u6eff\u6642\uff0c\u5beb\u5165\u64cd\u4f5c\u5c07\u8fd4\u56de\u932f\u8aa4\u3002<\/li>\n<li><code>allkeys-lru<\/code>: \u9a45\u9010\u6700\u5c11\u4f7f\u7528\u7684\u9375\u3002<\/li>\n<li><code>volatile-lru<\/code>: \u53ea\u9a45\u9010\u8a2d\u7f6e\u4e86\u904e\u671f\u6642\u9593\u7684\u9375\u3002<\/li>\n<li><code>allkeys-random<\/code>: \u96a8\u6a5f\u9a45\u9010\u9375\u3002<\/li>\n<li><code>volatile-random<\/code>: \u96a8\u6a5f\u9a45\u9010\u8a2d\u7f6e\u4e86\u904e\u671f\u6642\u9593\u7684\u9375\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u4f7f\u7528\u6700\u5c11\u4f7f\u7528\u7684\u9375\u9a45\u9010\u7b56\u7565\uff0c\u53ef\u4ee5\u9019\u6a23\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>maxmemory-policy allkeys-lru<\/code><\/pre>\n<h2 id=\"3-save-WCxrpRRiLc\">3. save<\/h2>\n<p>\u53c3\u6578 <code>save<\/code> \u7528\u65bc\u8a2d\u7f6eRedis\u7684\u6301\u4e45\u5316\u7b56\u7565\u3002\u5b83\u5b9a\u7fa9\u4e86\u5728\u591a\u9577\u6642\u9593\u5167\u6709\u591a\u5c11\u6b21\u5beb\u5165\u64cd\u4f5c\u5f8c\uff0cRedis\u6703\u81ea\u52d5\u5c07\u6578\u64da\u5feb\u7167\u4fdd\u5b58\u5230\u78c1\u789f\u4e2d\u3002\u9019\u5c0d\u65bc\u6578\u64da\u7684\u6301\u4e45\u6027\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u914d\u7f6e\u8868\u793a\u6bcf60\u79d2\u5167\u81f3\u5c11\u670910000\u6b21\u5beb\u5165\u64cd\u4f5c\u6642\uff0c\u5c07\u6578\u64da\u4fdd\u5b58\u5230\u78c1\u789f\uff1a<\/p>\n<pre><code>save 60 10000<\/code><\/pre>\n<h2 id=\"4-appendonly-WCxrpRRiLc\">4. appendonly<\/h2>\n<p>\u53c3\u6578 <code>appendonly<\/code> \u7528\u65bc\u555f\u7528\u6216\u7981\u7528\u8ffd\u52a0\u6587\u4ef6\u6301\u4e45\u5316\u3002\u7576\u8a2d\u7f6e\u70ba <code>yes<\/code> \u6642\uff0cRedis\u6703\u5c07\u6bcf\u6b21\u5beb\u5165\u64cd\u4f5c\u8ffd\u52a0\u5230\u4e00\u500b\u65e5\u8a8c\u6587\u4ef6\u4e2d\uff0c\u9019\u6a23\u53ef\u4ee5\u5728\u91cd\u555f\u5f8c\u6062\u5fa9\u6578\u64da\u3002<\/p>\n<p>\u8981\u555f\u7528\u8ffd\u52a0\u6587\u4ef6\u6301\u4e45\u5316\uff0c\u53ef\u4ee5\u9019\u6a23\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>appendonly yes<\/code><\/pre>\n<h2 id=\"5-timeout-WCxrpRRiLc\">5. timeout<\/h2>\n<p>\u53c3\u6578 <code>timeout<\/code> \u7528\u65bc\u8a2d\u7f6e\u5ba2\u6236\u7aef\u9023\u63a5\u7684\u8d85\u6642\u6642\u9593\u3002\u5982\u679c\u5728\u6307\u5b9a\u7684\u6642\u9593\u5167\u6c92\u6709\u4efb\u4f55\u64cd\u4f5c\uff0cRedis\u5c07\u81ea\u52d5\u95dc\u9589\u8a72\u9023\u63a5\u3002\u9019\u6709\u52a9\u65bc\u91cb\u653e\u8cc7\u6e90\uff0c\u7279\u5225\u662f\u5728\u9ad8\u4e26\u767c\u7684\u74b0\u5883\u4e2d\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u5c07\u8d85\u6642\u8a2d\u7f6e\u70ba300\u79d2\uff0c\u53ef\u4ee5\u9019\u6a23\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>timeout 300<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-WCxrpRRiLc\">\u7e3d\u7d50<\/h2>\n<p>\u4e86\u89e3Redis\u7684\u9019\u4e94\u500b\u91cd\u8981\u53c3\u6578\u53ca\u5176\u542b\u7fa9\uff0c\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u66f4\u6709\u6548\u5730\u914d\u7f6e\u548c\u7ba1\u7406Redis\u5be6\u4f8b\u3002\u901a\u904e\u5408\u7406\u8a2d\u7f6e <code>maxmemory<\/code>\u3001<code>maxmemory-policy<\/code>\u3001<code>save<\/code>\u3001<code>appendonly<\/code> \u548c <code>timeout<\/code>\uff0c\u7528\u6236\u53ef\u4ee5\u512a\u5316Redis\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u7528\u6236\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u6578\u64da\u5b58\u5132\u9084\u662f\u61c9\u7528\u90e8\u7f72\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u89e3\u8b80Redis\u4e2d\u4e94\u500b\u91cd\u8981\u53c3\u6578\u7684\u542b\u7fa9\uff0c\u5e6b\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u548c\u512a\u5316Redis\u6027\u80fd\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-180586","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180586","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=180586"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180586\/revisions"}],"predecessor-version":[{"id":180587,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180586\/revisions\/180587"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=180586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=180586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=180586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}