{"id":134251,"date":"2024-10-31T00:00:18","date_gmt":"2024-10-30T16:00:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/134251\/"},"modified":"2024-10-31T00:00:19","modified_gmt":"2024-10-30T16:00:19","slug":"redis%e6%87%89%e7%94%a8%e6%8e%8c%e6%8f%a1%e5%a4%a7%e5%b0%8f%e9%99%90%e5%88%b6%ef%bc%88redis%e8%a8%ad%e7%bd%aesize%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/134251\/","title":{"rendered":"Redis\u61c9\u7528\u638c\u63e1\u5927\u5c0f\u9650\u5236\uff08redis\u8a2d\u7f6esize\uff09"},"content":{"rendered":"<h1 id=\"redis%e6%87%89%e7%94%a8%e6%8e%8c%e6%8f%a1%e5%a4%a7%e5%b0%8f%e9%99%90%e5%88%b6%ef%bc%88redis%e8%a8%ad%e7%bd%aesize%ef%bc%89-wAzJaXxUWc\">Redis\u61c9\u7528\u638c\u63e1\u5927\u5c0f\u9650\u5236\uff08redis\u8a2d\u7f6esize\uff09<\/h1>\n<p>Redis\u662f\u4e00\u7a2e\u9ad8\u6548\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u6578\u64da\u5b58\u5132\u7b49\u5834\u666f\u3002\u7531\u65bc\u5176\u9ad8\u6027\u80fd\u548c\u9748\u6d3b\u6027\uff0c\u8a31\u591a\u958b\u767c\u8005\u9078\u64c7\u4f7f\u7528Redis\u4f86\u63d0\u5347\u61c9\u7528\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u53ef\u64f4\u5c55\u6027\u3002\u7136\u800c\uff0c\u5728\u4f7f\u7528Redis\u6642\uff0c\u4e86\u89e3\u5176\u5927\u5c0f\u9650\u5236\u53ca\u5982\u4f55\u8a2d\u7f6e\u9019\u4e9b\u9650\u5236\u662f\u81f3\u95dc\u91cd\u8981\u7684\uff0c\u9019\u4e0d\u50c5\u80fd\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7ba1\u7406\u8cc7\u6e90\uff0c\u9084\u80fd\u907f\u514d\u6f5b\u5728\u7684\u6027\u80fd\u554f\u984c\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%a4%a7%e5%b0%8f%e9%99%90%e5%88%b6-wAzJaXxUWc\">Redis\u7684\u5927\u5c0f\u9650\u5236<\/h2>\n<p>Redis\u7684\u5927\u5c0f\u9650\u5236\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u65b9\u9762\uff1a<\/p>\n<ul>\n<li><strong>\u55ae\u500b\u9375\u7684\u5927\u5c0f\u9650\u5236\uff1a<\/strong>Redis\u4e2d\u55ae\u500b\u9375\u7684\u6700\u5927\u5927\u5c0f\u70ba512MB\u3002\u9019\u610f\u5473\u8457\u5982\u679c\u4f60\u5617\u8a66\u5b58\u5132\u8d85\u904e\u6b64\u5927\u5c0f\u7684\u6578\u64da\uff0cRedis\u5c07\u7121\u6cd5\u63a5\u53d7\u3002<\/li>\n<li><strong>\u6578\u64da\u5eab\u7684\u5927\u5c0f\u9650\u5236\uff1a<\/strong>Redis\u7684\u6578\u64da\u5eab\u5927\u5c0f\u7406\u8ad6\u4e0a\u662f\u7121\u9650\u5236\u7684\uff0c\u4f46\u5be6\u969b\u4e0a\u53d7\u9650\u65bc\u53ef\u7528\u5167\u5b58\u3002\u7576Redis\u4f7f\u7528\u7684\u5167\u5b58\u8d85\u904e\u8a2d\u5b9a\u7684\u9650\u5236\u6642\uff0c\u5c07\u6839\u64da\u914d\u7f6e\u7684\u9a45\u9010\u7b56\u7565\u4f86\u522a\u9664\u820a\u6578\u64da\u3002<\/li>\n<li><strong>\u6574\u9ad4\u5167\u5b58\u9650\u5236\uff1a<\/strong>Redis\u7684\u5167\u5b58\u4f7f\u7528\u91cf\u53ef\u4ee5\u901a\u904e\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684`maxmemory`\u53c3\u6578\u4f86\u8a2d\u7f6e\u3002\u9019\u500b\u53c3\u6578\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u63a7\u5236Redis\u7684\u5167\u5b58\u4f7f\u7528\uff0c\u907f\u514d\u56e0\u70ba\u5167\u5b58\u6ea2\u51fa\u800c\u5c0e\u81f4\u7684\u670d\u52d9\u5d29\u6f70\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e8%a8%ad%e7%bd%aeredis%e7%9a%84%e5%a4%a7%e5%b0%8f%e9%99%90%e5%88%b6-wAzJaXxUWc\">\u5982\u4f55\u8a2d\u7f6eRedis\u7684\u5927\u5c0f\u9650\u5236<\/h2>\n<p>\u8981\u8a2d\u7f6eRedis\u7684\u5927\u5c0f\u9650\u5236\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u901a\u904e\u4fee\u6539Redis\u7684\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u662f`redis.conf`\uff09\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u914d\u7f6e\u9078\u9805\uff1a<\/p>\n<h3 id=\"1-%e8%a8%ad%e7%bd%ae%e6%9c%80%e5%a4%a7%e5%85%a7%e5%ad%98-wAzJaXxUWc\">1. \u8a2d\u7f6e\u6700\u5927\u5167\u5b58<\/h3>\n<pre><code>maxmemory 256mb<\/code><\/pre>\n<p>\u4e0a\u8ff0\u914d\u7f6e\u5c07Redis\u7684\u6700\u5927\u5167\u5b58\u9650\u5236\u8a2d\u7f6e\u70ba256MB\u3002\u7576Redis\u7684\u5167\u5b58\u4f7f\u7528\u91cf\u9054\u5230\u6b64\u9650\u5236\u6642\uff0c\u5c07\u6839\u64da\u9a45\u9010\u7b56\u7565\u522a\u9664\u820a\u6578\u64da\u3002<\/p>\n<h3 id=\"2-%e8%a8%ad%e7%bd%ae%e9%a9%85%e9%80%90%e7%ad%96%e7%95%a5-wAzJaXxUWc\">2. \u8a2d\u7f6e\u9a45\u9010\u7b56\u7565<\/h3>\n<p>Redis\u63d0\u4f9b\u4e86\u591a\u7a2e\u9a45\u9010\u7b56\u7565\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u7b56\u7565\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u9a45\u9010\u7b56\u7565\uff1a<\/p>\n<ul>\n<li><strong>noeviction\uff1a<\/strong>\u7576\u5167\u5b58\u9054\u5230\u9650\u5236\u6642\uff0c\u62d2\u7d55\u5beb\u5165\u64cd\u4f5c\u3002<\/li>\n<li><strong>allkeys-lru\uff1a<\/strong>\u6839\u64da\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\uff08LRU\uff09\u7b97\u6cd5\u9a45\u9010\u9375\u3002<\/li>\n<li><strong>volatile-lru\uff1a<\/strong>\u50c5\u9a45\u9010\u8a2d\u7f6e\u4e86\u904e\u671f\u6642\u9593\u7684\u9375\u3002<\/li>\n<\/ul>\n<pre><code>maxmemory-policy allkeys-lru<\/code><\/pre>\n<p>\u9019\u6bb5\u914d\u7f6e\u5c07\u9a45\u9010\u7b56\u7565\u8a2d\u7f6e\u70ba`allkeys-lru`\uff0c\u5373\u6839\u64daLRU\u7b97\u6cd5\u9a45\u9010\u6240\u6709\u9375\u3002<\/p>\n<h3 id=\"3-%e8%a8%ad%e7%bd%ae%e5%96%ae%e5%80%8b%e9%8d%b5%e7%9a%84%e5%a4%a7%e5%b0%8f%e9%99%90%e5%88%b6-wAzJaXxUWc\">3. \u8a2d\u7f6e\u55ae\u500b\u9375\u7684\u5927\u5c0f\u9650\u5236<\/h3>\n<p>\u96d6\u7136Redis\u672c\u8eab\u4e0d\u63d0\u4f9b\u76f4\u63a5\u8a2d\u7f6e\u55ae\u500b\u9375\u5927\u5c0f\u9650\u5236\u7684\u529f\u80fd\uff0c\u4f46\u958b\u767c\u8005\u53ef\u4ee5\u5728\u61c9\u7528\u5c64\u9762\u9032\u884c\u63a7\u5236\u3002\u4f8b\u5982\uff0c\u5728\u63d2\u5165\u6578\u64da\u4e4b\u524d\uff0c\u6aa2\u67e5\u6578\u64da\u7684\u5927\u5c0f\uff0c\u78ba\u4fdd\u4e0d\u8d85\u904e512MB\u7684\u9650\u5236\u3002<\/p>\n<pre><code>if (strlen($data) &gt; 512 * 1024 * 1024) {\n    throw new Exception(\"\u9375\u7684\u5927\u5c0f\u8d85\u904e\u9650\u5236\");\n}<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-wAzJaXxUWc\">\u7d50\u8ad6<\/h2>\n<p>\u638c\u63e1Redis\u7684\u5927\u5c0f\u9650\u5236\u53ca\u5176\u8a2d\u7f6e\u65b9\u6cd5\u5c0d\u65bc\u958b\u767c\u8005\u4f86\u8aaa\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e\u5167\u5b58\u9650\u5236\u548c\u9a45\u9010\u7b56\u7565\uff0c\u53ef\u4ee5\u6709\u6548\u7ba1\u7406Redis\u7684\u6027\u80fd\u548c\u8cc7\u6e90\u4f7f\u7528\uff0c\u907f\u514d\u6f5b\u5728\u7684\u554f\u984c\u3002\u5728\u9078\u64c7\u5408\u9069\u7684\u914d\u7f6e\u6642\uff0c\u958b\u767c\u8005\u61c9\u6839\u64da\u5be6\u969b\u9700\u6c42\u9032\u884c\u8abf\u6574\uff0c\u4ee5\u78ba\u4fdd\u61c9\u7528\u7684\u7a69\u5b9a\u6027\u548c\u9ad8\u6548\u6027\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc<code>VPS<\/code>\u3001<code>\u9999\u6e2fVPS<\/code>\u53ca<code>\u4e91\u670d\u52a1\u5668<\/code>\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9 <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Redis\u61c9\u7528\u4e2d\u7684\u5927\u5c0f\u9650\u5236\u8a2d\u7f6e\uff0c\u638c\u63e1\u5982\u4f55\u6709\u6548\u7ba1\u7406\u6578\u64da\u5b58\u5132\uff0c\u63d0\u5347\u6027\u80fd\u8207\u6548\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-134251","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/134251","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=134251"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/134251\/revisions"}],"predecessor-version":[{"id":134252,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/134251\/revisions\/134252"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=134251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=134251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=134251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}