{"id":99324,"date":"2024-10-21T10:02:17","date_gmt":"2024-10-21T02:02:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/99324\/"},"modified":"2024-10-21T10:02:18","modified_gmt":"2024-10-21T02:02:18","slug":"redis-%e9%ab%98%e4%b8%a6%e7%99%bc%e7%92%b0%e5%a2%83%e4%b8%ad%e7%9a%84%e5%bf%ab%e5%8f%96%e5%a4%b1%e6%95%88%e5%95%8f%e9%a1%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/99324\/","title":{"rendered":"Redis \u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\u7684\u5feb\u53d6\u5931\u6548\u554f\u984c"},"content":{"rendered":"<h1 id=\"redis-%e9%ab%98%e4%b8%a6%e7%99%bc%e7%92%b0%e5%a2%83%e4%b8%ad%e7%9a%84%e5%bf%ab%e5%8f%96%e5%a4%b1%e6%95%88%e5%95%8f%e9%a1%8c-xGOZIoUrBP\">Redis \u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\u7684\u5feb\u53d6\u5931\u6548\u554f\u984c<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u61c9\u7528\u4e2d\uff0cRedis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\u3002\u5b83\u7684\u5feb\u901f\u8b80\u53d6\u548c\u5beb\u5165\u80fd\u529b\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u6709\u6548\u5730\u63d0\u5347\u61c9\u7528\u6027\u80fd\u3002\u7136\u800c\uff0c\u5728\u9ad8\u4e26\u767c\u7684\u60c5\u6cc1\u4e0b\uff0c\u5feb\u53d6\u5931\u6548\u554f\u984c\u537b\u6210\u70ba\u4e86\u4e00\u500b\u4e0d\u5bb9\u5ffd\u8996\u7684\u6311\u6230\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Redis \u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\u7684\u5feb\u53d6\u5931\u6548\u554f\u984c\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e5%bf%ab%e5%8f%96%e5%a4%b1%e6%95%88%e7%9a%84%e5%8e%9f%e5%9b%a0-xGOZIoUrBP\">\u5feb\u53d6\u5931\u6548\u7684\u539f\u56e0<\/h2>\n<p>\u5feb\u53d6\u5931\u6548\u901a\u5e38\u662f\u6307\u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\uff0c\u5feb\u53d6\u4e2d\u7684\u6578\u64da\u56e0\u67d0\u4e9b\u539f\u56e0\u800c\u7121\u6cd5\u6b63\u5e38\u4f7f\u7528\u3002\u4ee5\u4e0b\u662f\u5e7e\u500b\u5e38\u898b\u7684\u539f\u56e0\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u66f4\u65b0\u983b\u7e41\uff1a<\/strong>\u7576\u6578\u64da\u6e90\u983b\u7e41\u66f4\u65b0\u6642\uff0c\u5feb\u53d6\u4e2d\u7684\u6578\u64da\u53ef\u80fd\u6703\u904e\u6642\uff0c\u5c0e\u81f4\u5feb\u53d6\u5931\u6548\u3002<\/li>\n<li><strong>\u5feb\u53d6\u7a7f\u900f\uff1a<\/strong>\u7576\u8acb\u6c42\u7684\u6578\u64da\u5728\u5feb\u53d6\u4e2d\u4e0d\u5b58\u5728\u6642\uff0c\u7cfb\u7d71\u6703\u76f4\u63a5\u67e5\u8a62\u6578\u64da\u5eab\uff0c\u9019\u53ef\u80fd\u5c0e\u81f4\u5927\u91cf\u7684\u8acb\u6c42\u76f4\u63a5\u6253\u5230\u6578\u64da\u5eab\uff0c\u9020\u6210\u58d3\u529b\u3002<\/li>\n<li><strong>\u5feb\u53d6\u96ea\u5d29\uff1a<\/strong>\u7576\u5927\u91cf\u7684\u5feb\u53d6\u540c\u6642\u904e\u671f\u6642\uff0c\u6703\u5c0e\u81f4\u77ac\u9593\u5927\u91cf\u8acb\u6c42\u6253\u5230\u6578\u64da\u5eab\uff0c\u9020\u6210\u7cfb\u7d71\u5d29\u6f70\u3002<\/li>\n<li><strong>\u5feb\u53d6\u64ca\u7a7f\uff1a<\/strong>\u7576\u67d0\u500b\u71b1\u9580\u6578\u64da\u7684\u5feb\u53d6\u5931\u6548\u6642\uff0c\u6240\u6709\u8acb\u6c42\u90fd\u6703\u76f4\u63a5\u67e5\u8a62\u6578\u64da\u5eab\uff0c\u9020\u6210\u77ac\u9593\u7684\u6d41\u91cf\u6fc0\u589e\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%bf%ab%e5%8f%96%e5%a4%b1%e6%95%88%e7%9a%84%e5%bd%b1%e9%9f%bf-xGOZIoUrBP\">\u5feb\u53d6\u5931\u6548\u7684\u5f71\u97ff<\/h2>\n<p>\u5feb\u53d6\u5931\u6548\u6703\u5c0d\u7cfb\u7d71\u6027\u80fd\u9020\u6210\u56b4\u91cd\u5f71\u97ff\uff0c\u5177\u9ad4\u8868\u73fe\u5728\u4ee5\u4e0b\u5e7e\u500b\u65b9\u9762\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u4e0b\u964d\uff1a<\/strong>\u5feb\u53d6\u5931\u6548\u6703\u5c0e\u81f4\u7cfb\u7d71\u983b\u7e41\u8a2a\u554f\u6578\u64da\u5eab\uff0c\u589e\u52a0\u4e86\u5ef6\u9072\uff0c\u964d\u4f4e\u4e86\u6574\u9ad4\u6027\u80fd\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u6d6a\u8cbb\uff1a<\/strong>\u5927\u91cf\u7684\u6578\u64da\u5eab\u8acb\u6c42\u6703\u6d88\u8017\u66f4\u591a\u7684\u8a08\u7b97\u8cc7\u6e90\uff0c\u589e\u52a0\u4e86\u904b\u884c\u6210\u672c\u3002<\/li>\n<li><strong>\u7528\u6236\u9ad4\u9a57\u4e0b\u964d\uff1a<\/strong>\u7531\u65bc\u5ef6\u9072\u589e\u52a0\uff0c\u7528\u6236\u5728\u4f7f\u7528\u61c9\u7528\u6642\u7684\u9ad4\u9a57\u6703\u53d7\u5230\u5f71\u97ff\uff0c\u53ef\u80fd\u5c0e\u81f4\u7528\u6236\u6d41\u5931\u3002<\/li>\n<\/ul>\n<h2 id=\"%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-xGOZIoUrBP\">\u89e3\u6c7a\u65b9\u6848<\/h2>\n<p>\u70ba\u4e86\u6709\u6548\u89e3\u6c7a Redis \u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\u7684\u5feb\u53d6\u5931\u6548\u554f\u984c\uff0c\u53ef\u4ee5\u8003\u616e\u4ee5\u4e0b\u5e7e\u7a2e\u7b56\u7565\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8%e5%90%88%e7%90%86%e7%9a%84%e5%bf%ab%e5%8f%96%e7%ad%96%e7%95%a5-xGOZIoUrBP\">1. \u4f7f\u7528\u5408\u7406\u7684\u5feb\u53d6\u7b56\u7565<\/h3>\n<p>\u9078\u64c7\u5408\u9069\u7684\u5feb\u53d6\u904e\u671f\u7b56\u7565\u662f\u95dc\u9375\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u96a8\u6a5f\u904e\u671f\u6642\u9593\u4f86\u907f\u514d\u5feb\u53d6\u96ea\u5d29\u7684\u60c5\u6cc1\u3002\u9019\u6a23\u53ef\u4ee5\u4f7f\u5f97\u5feb\u53d6\u7684\u904e\u671f\u6642\u9593\u5206\u6563\uff0c\u6e1b\u5c11\u540c\u6642\u904e\u671f\u7684\u60c5\u6cc1\u3002<\/p>\n<pre><code>\nSET key value EX 300\n<\/code><\/pre>\n<h3 id=\"2-%e5%af%a6%e7%8f%be%e9%9b%99%e9%87%8d%e9%8e%96%e5%ae%9a-xGOZIoUrBP\">2. \u5be6\u73fe\u96d9\u91cd\u9396\u5b9a<\/h3>\n<p>\u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u96d9\u91cd\u9396\u5b9a\u4f86\u907f\u514d\u5feb\u53d6\u64ca\u7a7f\u7684\u554f\u984c\u3002\u7576\u5feb\u53d6\u5931\u6548\u6642\uff0c\u5148\u6aa2\u67e5\u5feb\u53d6\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5247\u52a0\u9396\uff0c\u7136\u5f8c\u518d\u67e5\u8a62\u6578\u64da\u5eab\u3002<\/p>\n<pre><code>\nif (cache.get(key) == null) {\n    synchronized (lock) {\n        if (cache.get(key) == null) {\n            value = db.get(key);\n            cache.put(key, value);\n        }\n    }\n}\n<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8%e5%b8%83%e9%9a%86%e9%81%8e%e6%bf%be%e5%99%a8-xGOZIoUrBP\">3. \u4f7f\u7528\u5e03\u9686\u904e\u6ffe\u5668<\/h3>\n<p>\u5e03\u9686\u904e\u6ffe\u5668\u53ef\u4ee5\u6709\u6548\u5730\u6e1b\u5c11\u5c0d\u6578\u64da\u5eab\u7684\u8acb\u6c42\u3002\u7576\u8acb\u6c42\u7684\u6578\u64da\u4e0d\u5728\u5feb\u53d6\u4e2d\u6642\uff0c\u5148\u901a\u904e\u5e03\u9686\u904e\u6ffe\u5668\u6aa2\u67e5\u6578\u64da\u662f\u5426\u5b58\u5728\uff0c\u5f9e\u800c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u5eab\u67e5\u8a62\u3002<\/p>\n<pre><code>\nif (!bloomFilter.mightContain(key)) {\n    \/\/ \u4e0d\u5b58\u5728\uff0c\u76f4\u63a5\u8fd4\u56de\n}\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-xGOZIoUrBP\">\u7d50\u8ad6<\/h2>\n<p>\u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\uff0cRedis \u7684\u5feb\u53d6\u5931\u6548\u554f\u984c\u662f\u958b\u767c\u8005\u9700\u8981\u91cd\u8996\u7684\u6311\u6230\u3002\u901a\u904e\u5408\u7406\u7684\u5feb\u53d6\u7b56\u7565\u3001\u96d9\u91cd\u9396\u5b9a\u548c\u5e03\u9686\u904e\u6ffe\u5668\u7b49\u6280\u8853\u624b\u6bb5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u6e1b\u5c11\u5feb\u53d6\u5931\u6548\u5e36\u4f86\u7684\u5f71\u97ff\uff0c\u63d0\u5347\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u6027\u80fd\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u548c\u4f3a\u670d\u5668\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u8a0eRedis\u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\u5feb\u53d6\u5931\u6548\u7684\u554f\u984c\u53ca\u89e3\u6c7a\u65b9\u6848\uff0c\u63d0\u5347\u7cfb\u7d71\u6548\u80fd\u8207\u7a69\u5b9a\u6027\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-99324","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/99324","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=99324"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/99324\/revisions"}],"predecessor-version":[{"id":99325,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/99324\/revisions\/99325"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=99324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=99324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=99324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}