{"id":152011,"date":"2024-11-01T19:21:21","date_gmt":"2024-11-01T11:21:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/152011\/"},"modified":"2024-11-01T19:21:22","modified_gmt":"2024-11-01T11:21:22","slug":"%e5%b4%a9%e5%a0%a1%e5%a3%98%e6%8a%b5%e6%8a%97redis%e5%bf%ab%e5%8f%96%e9%9b%aa%e5%b4%a9%ef%bc%88redis%e5%bf%ab%e5%8f%96%e9%9b%aa%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/152011\/","title":{"rendered":"\u5d29\u5821\u58d8\u62b5\u6297Redis\u5feb\u53d6\u96ea\u5d29\uff08redis\u5feb\u53d6\u96ea\uff09"},"content":{"rendered":"<h1 id=\"%e5%b4%a9%e5%a0%a1%e5%a3%98%e6%8a%b5%e6%8a%97redis%e5%bf%ab%e5%8f%96%e9%9b%aa%e5%b4%a9%ef%bc%88redis%e5%bf%ab%e5%8f%96%e9%9b%aa%ef%bc%89-VurdrcOGMM\">\u5d29\u5821\u58d8\u62b5\u6297Redis\u5feb\u53d6\u96ea\u5d29\uff08redis\u5feb\u53d6\u96ea\uff09<\/h1>\n<p>\u5728\u73fe\u4ee3\u7684\u7db2\u8def\u61c9\u7528\u4e2d\uff0cRedis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u63d0\u5347\u7cfb\u7d71\u6027\u80fd\u548c\u97ff\u61c9\u901f\u5ea6\u3002\u7136\u800c\uff0c\u96a8\u8457\u4f7f\u7528\u91cf\u7684\u589e\u52a0\uff0cRedis\u5feb\u53d6\u96ea\u5d29\u7684\u554f\u984c\u4e5f\u9010\u6f38\u6d6e\u73fe\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eRedis\u5feb\u53d6\u96ea\u5d29\u7684\u6210\u56e0\u3001\u5f71\u97ff\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u61c9\u5c0d\u9019\u4e00\u6311\u6230\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%e5%bf%ab%e5%8f%96%e9%9b%aa%e5%b4%a9%ef%bc%9f-VurdrcOGMM\">\u4ec0\u9ebc\u662fRedis\u5feb\u53d6\u96ea\u5d29\uff1f<\/h2>\n<p>Redis\u5feb\u53d6\u96ea\u5d29\u662f\u6307\u5728\u67d0\u4e00\u6642\u9593\u6bb5\u5167\uff0c\u5927\u91cf\u7684\u5feb\u53d6\u6578\u64da\u540c\u6642\u904e\u671f\uff0c\u5c0e\u81f4\u5927\u91cf\u8acb\u6c42\u76f4\u63a5\u6253\u5230\u5f8c\u7aef\u6578\u64da\u5eab\uff0c\u9020\u6210\u6578\u64da\u5eab\u7684\u77ac\u6642\u8ca0\u8f09\u6fc0\u589e\uff0c\u6700\u7d42\u53ef\u80fd\u5c0e\u81f4\u7cfb\u7d71\u5d29\u6f70\u3002\u9019\u7a2e\u60c5\u6cc1\u901a\u5e38\u767c\u751f\u5728\u9ad8\u6d41\u91cf\u7684\u61c9\u7528\u4e2d\uff0c\u7279\u5225\u662f\u5728\u7279\u5b9a\u7684\u6642\u9593\u9ede\uff0c\u4f8b\u5982\u4fc3\u92b7\u6d3b\u52d5\u6216\u7279\u5b9a\u7684\u7528\u6236\u884c\u70ba\u6a21\u5f0f\u3002<\/p>\n<h2 id=\"%e5%bf%ab%e5%8f%96%e9%9b%aa%e5%b4%a9%e7%9a%84%e6%88%90%e5%9b%a0-VurdrcOGMM\">\u5feb\u53d6\u96ea\u5d29\u7684\u6210\u56e0<\/h2>\n<ul>\n<li><strong>\u5927\u91cf\u6578\u64da\u540c\u6642\u904e\u671f\uff1a<\/strong>\u5982\u679c\u5feb\u53d6\u4e2d\u7684\u6578\u64da\u5728\u76f8\u540c\u7684\u6642\u9593\u5167\u904e\u671f\uff0c\u5c07\u6703\u5c0e\u81f4\u5927\u91cf\u8acb\u6c42\u540c\u6642\u6e67\u5165\u5f8c\u7aef\u7cfb\u7d71\u3002<\/li>\n<li><strong>\u4e0d\u5747\u52fb\u7684\u6d41\u91cf\u5206\u4f48\uff1a<\/strong>\u5728\u67d0\u4e9b\u7279\u5b9a\u6642\u9593\u6bb5\u5167\uff0c\u6d41\u91cf\u7684\u6fc0\u589e\u53ef\u80fd\u6703\u5c0e\u81f4\u5feb\u53d6\u7684\u5931\u6548\u3002<\/li>\n<li><strong>\u5feb\u53d6\u5931\u6548\u7b56\u7565\u4e0d\u7576\uff1a<\/strong>\u5982\u679c\u5feb\u53d6\u7684\u5931\u6548\u7b56\u7565\u8a2d\u7f6e\u4e0d\u7576\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u5feb\u53d6\u6578\u64da\u7684\u904e\u671f\u6642\u9593\u904e\u65bc\u96c6\u4e2d\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%bf%ab%e5%8f%96%e9%9b%aa%e5%b4%a9%e7%9a%84%e5%bd%b1%e9%9f%bf-VurdrcOGMM\">\u5feb\u53d6\u96ea\u5d29\u7684\u5f71\u97ff<\/h2>\n<p>\u5feb\u53d6\u96ea\u5d29\u6703\u5c0d\u7cfb\u7d71\u9020\u6210\u56b4\u91cd\u5f71\u97ff\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u7cfb\u7d71\u6027\u80fd\u4e0b\u964d\uff1a<\/strong>\u5927\u91cf\u8acb\u6c42\u76f4\u63a5\u6253\u5230\u6578\u64da\u5eab\uff0c\u53ef\u80fd\u5c0e\u81f4\u6578\u64da\u5eab\u7684\u6027\u80fd\u4e0b\u964d\uff0c\u5f71\u97ff\u6574\u9ad4\u7cfb\u7d71\u7684\u97ff\u61c9\u901f\u5ea6\u3002<\/li>\n<li><strong>\u670d\u52d9\u4e0d\u53ef\u7528\uff1a<\/strong>\u5728\u6975\u7aef\u60c5\u6cc1\u4e0b\uff0c\u6578\u64da\u5eab\u53ef\u80fd\u56e0\u70ba\u904e\u8f09\u800c\u7121\u6cd5\u63d0\u4f9b\u670d\u52d9\uff0c\u5c0e\u81f4\u7528\u6236\u9ad4\u9a57\u4e0b\u964d\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u6d6a\u8cbb\uff1a<\/strong>\u7cfb\u7d71\u8cc7\u6e90\u7684\u6d6a\u8cbb\u6703\u589e\u52a0\u904b\u71df\u6210\u672c\uff0c\u4e26\u53ef\u80fd\u5f71\u97ff\u5176\u4ed6\u6b63\u5e38\u904b\u884c\u7684\u670d\u52d9\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e9%98%b2%e6%ad%a2redis%e5%bf%ab%e5%8f%96%e9%9b%aa%e5%b4%a9-VurdrcOGMM\">\u5982\u4f55\u9632\u6b62Redis\u5feb\u53d6\u96ea\u5d29<\/h2>\n<p>\u70ba\u4e86\u6709\u6548\u9632\u6b62Redis\u5feb\u53d6\u96ea\u5d29\uff0c\u53ef\u4ee5\u63a1\u53d6\u4ee5\u4e0b\u5e7e\u7a2e\u7b56\u7565\uff1a<\/p>\n<h3 id=\"1-%e9%9a%a8%e6%a9%9f%e9%81%8e%e6%9c%9f%e6%99%82%e9%96%93-VurdrcOGMM\">1. \u96a8\u6a5f\u904e\u671f\u6642\u9593<\/h3>\n<p>\u70ba\u4e86\u907f\u514d\u5927\u91cf\u6578\u64da\u540c\u6642\u904e\u671f\uff0c\u53ef\u4ee5\u70ba\u6bcf\u500b\u5feb\u53d6\u9805\u8a2d\u7f6e\u96a8\u6a5f\u7684\u904e\u671f\u6642\u9593\u3002\u9019\u6a23\u53ef\u4ee5\u6709\u6548\u5730\u5206\u6563\u5feb\u53d6\u7684\u904e\u671f\u6642\u9593\uff0c\u6e1b\u5c11\u540c\u6642\u5931\u6548\u7684\u60c5\u6cc1\u3002<\/p>\n<pre><code>\nfunction setCacheWithRandomExpiry(key, value) {\n    const randomExpiry = Math.floor(Math.random() * (60 - 30 + 1)) + 30; \/\/ \u96a8\u6a5f30\u523060\u79d2\n    redisClient.setex(key, randomExpiry, value);\n}\n<\/code><\/pre>\n<h3 id=\"2-%e7%86%b1%e9%bb%9e%e6%95%b8%e6%93%9a%e7%9a%84%e9%a0%90%e7%86%b1-VurdrcOGMM\">2. \u71b1\u9ede\u6578\u64da\u7684\u9810\u71b1<\/h3>\n<p>\u5c0d\u65bc\u9810\u671f\u6703\u6709\u9ad8\u6d41\u91cf\u7684\u71b1\u9ede\u6578\u64da\uff0c\u53ef\u4ee5\u63d0\u524d\u5c07\u5176\u52a0\u8f09\u5230\u5feb\u53d6\u4e2d\uff0c\u907f\u514d\u5728\u6d41\u91cf\u9ad8\u5cf0\u671f\u51fa\u73fe\u5feb\u53d6\u5931\u6548\u7684\u60c5\u6cc1\u3002<\/p>\n<h3 id=\"3-%e9%99%90%e6%b5%81%e6%8e%aa%e6%96%bd-VurdrcOGMM\">3. \u9650\u6d41\u63aa\u65bd<\/h3>\n<p>\u5728\u9ad8\u6d41\u91cf\u7684\u60c5\u6cc1\u4e0b\uff0c\u53ef\u4ee5\u901a\u904e\u9650\u6d41\u63aa\u65bd\u4f86\u63a7\u5236\u8acb\u6c42\u7684\u6578\u91cf\uff0c\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u58d3\u529b\u3002<\/p>\n<h3 id=\"4-%e4%bd%bf%e7%94%a8%e5%a4%9a%e5%b1%a4%e5%bf%ab%e5%8f%96-VurdrcOGMM\">4. \u4f7f\u7528\u591a\u5c64\u5feb\u53d6<\/h3>\n<p>\u53ef\u4ee5\u8003\u616e\u4f7f\u7528\u591a\u5c64\u5feb\u53d6\u67b6\u69cb\uff0c\u4f8b\u5982\u5728Redis\u4e4b\u4e0a\u518d\u52a0\u4e00\u5c64\u672c\u5730\u5feb\u53d6\uff0c\u9019\u6a23\u5373\u4f7fRedis\u51fa\u73fe\u554f\u984c\uff0c\u672c\u5730\u5feb\u53d6\u4ecd\u7136\u53ef\u4ee5\u63d0\u4f9b\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-VurdrcOGMM\">\u7d50\u8ad6<\/h2>\n<p>Redis\u5feb\u53d6\u96ea\u5d29\u662f\u4e00\u500b\u9700\u8981\u91cd\u8996\u7684\u554f\u984c\uff0c\u7279\u5225\u662f\u5728\u9ad8\u6d41\u91cf\u7684\u61c9\u7528\u4e2d\u3002\u901a\u904e\u5408\u7406\u7684\u8a2d\u8a08\u548c\u7b56\u7565\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u6e1b\u5c11\u5feb\u53d6\u96ea\u5d29\u7684\u98a8\u96aa\uff0c\u4fdd\u8b49\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u6027\u80fd\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u9ad8\u6027\u80fd\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684\u5feb\u53d6\u7b56\u7565\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc\u65bc<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u548c<code><a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a><\/code>\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5d29\u5821\u58d8\u62b5\u6297Redis\u5feb\u53d6\u96ea\u5d29\uff0c\u78ba\u4fdd\u7cfb\u7d71\u7a69\u5b9a\u6027\u8207\u6548\u80fd\uff0c\u907f\u514d\u5927\u898f\u6a21\u8acb\u6c42\u5c0e\u81f4\u7684\u670d\u52d9\u4e2d\u65b7\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-152011","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152011","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=152011"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152011\/revisions"}],"predecessor-version":[{"id":152012,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152011\/revisions\/152012"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=152011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=152011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=152011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}