{"id":189034,"date":"2024-11-12T04:01:22","date_gmt":"2024-11-11T20:01:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/189034\/"},"modified":"2024-11-12T04:01:23","modified_gmt":"2024-11-11T20:01:23","slug":"%e6%8f%90%e9%ab%98%e7%b3%bb%e7%b5%b1%e6%80%a7%e8%83%bd%e5%88%a9%e7%94%a8redis%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5%ef%bc%88%e4%bd%bf%e7%94%a8redis%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/189034\/","title":{"rendered":"\u63d0\u9ad8\u7cfb\u7d71\u6027\u80fd\u5229\u7528Redis\u5feb\u53d6\u7b56\u7565\uff08\u4f7f\u7528redis\u5feb\u53d6\u7b56\u7565\uff09"},"content":{"rendered":"<h1 id=\"%e6%8f%90%e9%ab%98%e7%b3%bb%e7%b5%b1%e6%80%a7%e8%83%bd%e5%88%a9%e7%94%a8redis%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5-BGMVarAPIx\">\u63d0\u9ad8\u7cfb\u7d71\u6027\u80fd\u5229\u7528Redis\u5feb\u53d6\u7b56\u7565<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7cfb\u7d71\u6027\u80fd\u7684\u512a\u5316\u5c0d\u65bc\u63d0\u4f9b\u826f\u597d\u7684\u7528\u6236\u9ad4\u9a57\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u6fc0\u589e\uff0c\u5982\u4f55\u6709\u6548\u5730\u7ba1\u7406\u548c\u5b58\u53d6\u6578\u64da\u6210\u70ba\u4e86\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u9762\u81e8\u7684\u4e00\u5927\u6311\u6230\u3002Redis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5167\u5b58\u6578\u64da\u7d50\u69cb\u5b58\u5132\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u5feb\u53d6\u7b56\u7565\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u7cfb\u7d71\u6027\u80fd\u3002\u672c\u6587\u5c07\u63a2\u8a0eRedis\u7684\u5feb\u53d6\u7b56\u7565\u53ca\u5176\u5728\u7cfb\u7d71\u6027\u80fd\u63d0\u5347\u4e2d\u7684\u61c9\u7528\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%ef%bc%9f-BGMVarAPIx\">\u4ec0\u9ebc\u662fRedis\uff1f<\/h2>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u500b\u958b\u6e90\u7684\u9ad8\u6027\u80fd\u9375\u503c\u6578\u64da\u5eab\uff0c\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u5982\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c\u3001\u5217\u8868\u3001\u96c6\u5408\u7b49\u3002\u7531\u65bc\u5176\u9ad8\u6548\u7684\u5167\u5b58\u5b58\u53d6\u7279\u6027\uff0cRedis\u88ab\u5ee3\u6cdb\u61c9\u7528\u65bc\u5feb\u53d6\u3001\u6d88\u606f\u968a\u5217\u548c\u5be6\u6642\u6578\u64da\u5206\u6790\u7b49\u5834\u666f\u3002<\/p>\n<h2 id=\"redis%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5%e6%a6%82%e8%bf%b0-BGMVarAPIx\">Redis\u5feb\u53d6\u7b56\u7565\u6982\u8ff0<\/h2>\n<p>Redis\u63d0\u4f9b\u4e86\u591a\u7a2e\u5feb\u53d6\u7b56\u7565\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u6839\u64da\u4e0d\u540c\u7684\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u65b9\u6848\u3002\u4ee5\u4e0b\u662f\u5e7e\u7a2e\u5e38\u898b\u7684\u5feb\u53d6\u7b56\u7565\uff1a<\/p>\n<ul>\n<li><strong>LRU\uff08Least Recently Used\uff09<\/strong>\uff1a\u9019\u7a2e\u7b56\u7565\u6703\u79fb\u9664\u6700\u4e45\u672a\u88ab\u4f7f\u7528\u7684\u6578\u64da\uff0c\u9069\u5408\u7528\u65bc\u9700\u8981\u4fdd\u6301\u6d3b\u8e8d\u6578\u64da\u7684\u5834\u666f\u3002<\/li>\n<li><strong>LFU\uff08Least Frequently Used\uff09<\/strong>\uff1a\u6b64\u7b56\u7565\u6703\u79fb\u9664\u4f7f\u7528\u983b\u7387\u6700\u4f4e\u7684\u6578\u64da\uff0c\u9069\u5408\u7528\u65bc\u9577\u671f\u4f7f\u7528\u7684\u6578\u64da\u3002<\/li>\n<li><strong>TTL\uff08Time To Live\uff09<\/strong>\uff1a\u8a2d\u7f6e\u6578\u64da\u7684\u6709\u6548\u6642\u9593\uff0c\u904e\u671f\u5f8c\u81ea\u52d5\u522a\u9664\uff0c\u9069\u5408\u7528\u65bc\u81e8\u6642\u6578\u64da\u7684\u5feb\u53d6\u3002<\/li>\n<\/ul>\n<h2 id=\"redis%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5%e7%9a%84%e5%af%a6%e7%8f%be-BGMVarAPIx\">Redis\u5feb\u53d6\u7b56\u7565\u7684\u5be6\u73fe<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u5feb\u53d6\u7b56\u7565\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u4ee3\u78bc\uff0c\u5c55\u793a\u5982\u4f55\u5728Redis\u4e2d\u5be6\u73fe\u9019\u4e9b\u7b56\u7565\u3002<\/p>\n<h3 id=\"1-lru%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5-BGMVarAPIx\">1. LRU\u5feb\u53d6\u7b56\u7565<\/h3>\n<pre><code>\n# \u8a2d\u7f6e\u6700\u5927\u5167\u5b58\u70ba100MB\nCONFIG SET maxmemory 100mb\n# \u8a2d\u7f6e\u5feb\u53d6\u7b56\u7565\u70baLRU\nCONFIG SET maxmemory-policy allkeys-lru\n<\/code><\/pre>\n<h3 id=\"2-lfu%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5-BGMVarAPIx\">2. LFU\u5feb\u53d6\u7b56\u7565<\/h3>\n<pre><code>\n# \u8a2d\u7f6e\u6700\u5927\u5167\u5b58\u70ba100MB\nCONFIG SET maxmemory 100mb\n# \u8a2d\u7f6e\u5feb\u53d6\u7b56\u7565\u70baLFU\nCONFIG SET maxmemory-policy allkeys-lfu\n<\/code><\/pre>\n<h3 id=\"3-ttl%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5-BGMVarAPIx\">3. TTL\u5feb\u53d6\u7b56\u7565<\/h3>\n<pre><code>\n# \u8a2d\u7f6e\u4e00\u500b\u9375\u7684\u503c\u4e26\u8a2d\u7f6e\u904e\u671f\u6642\u9593\u70ba60\u79d2\nSET mykey \"Hello\"\nEXPIRE mykey 60\n<\/code><\/pre>\n<h2 id=\"redis%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5%e7%9a%84%e5%84%aa%e5%8b%a2-BGMVarAPIx\">Redis\u5feb\u53d6\u7b56\u7565\u7684\u512a\u52e2<\/h2>\n<p>\u4f7f\u7528Redis\u5feb\u53d6\u7b56\u7565\u53ef\u4ee5\u5e36\u4f86\u591a\u65b9\u9762\u7684\u512a\u52e2\uff1a<\/p>\n<ul>\n<li><strong>\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6<\/strong>\uff1a\u901a\u904e\u5c07\u71b1\u6578\u64da\u5b58\u5132\u5728\u5167\u5b58\u4e2d\uff0cRedis\u80fd\u5920\u986f\u8457\u6e1b\u5c11\u6578\u64da\u5b58\u53d6\u7684\u5ef6\u9072\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u6578\u64da\u5eab\u8ca0\u64d4<\/strong>\uff1a\u5feb\u53d6\u5e38\u7528\u6578\u64da\u53ef\u4ee5\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u8acb\u6c42\uff0c\u5f9e\u800c\u964d\u4f4e\u6578\u64da\u5eab\u7684\u8ca0\u64d4\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\u9ad8<\/strong>\uff1aRedis\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\u548c\u5feb\u53d6\u7b56\u7565\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9748\u6d3b\u9078\u64c7\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-BGMVarAPIx\">\u7d50\u8ad6<\/h2>\n<p>Redis\u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u6709\u6548\u63d0\u5347\u7cfb\u7d71\u6027\u80fd\u3002\u901a\u904e\u5408\u7406\u9078\u64c7\u548c\u5be6\u73fe\u5feb\u53d6\u7b56\u7565\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5728\u4fdd\u8b49\u6578\u64da\u4e00\u81f4\u6027\u7684\u540c\u6642\uff0c\u986f\u8457\u63d0\u9ad8\u61c9\u7528\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u7a69\u5b9a\u6027\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u7684\u61c9\u7528\u4f86\u8aaa\uff0cRedis\u7121\u7591\u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u512a\u5316\u7cfb\u7d71\u6027\u80fd\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5229\u7528Redis\u5feb\u53d6\u7b56\u7565\u63d0\u5347\u7cfb\u7d71\u6027\u80fd\uff0c\u512a\u5316\u6578\u64da\u5b58\u53d6\u901f\u5ea6\uff0c\u5be6\u73fe\u9ad8\u6548\u80fd\u61c9\u7528\u7a0b\u5f0f\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-189034","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189034","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=189034"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189034\/revisions"}],"predecessor-version":[{"id":189035,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189034\/revisions\/189035"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=189034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=189034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=189034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}