{"id":164187,"date":"2024-11-05T05:45:33","date_gmt":"2024-11-04T21:45:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/164187\/"},"modified":"2024-11-05T05:45:34","modified_gmt":"2024-11-04T21:45:34","slug":"%e5%80%9f%e5%8a%a9redis%e5%af%a6%e7%8f%be%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e7%9a%84%e6%a7%8b%e5%bb%ba%e4%b9%8b%e9%81%93%ef%bc%88redis%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e5%a0%b4%e6%99%af%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/164187\/","title":{"rendered":"\u501f\u52a9Redis\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u7684\u69cb\u5efa\u4e4b\u9053\uff08redis\u8b80\u5beb\u5206\u96e2\u5834\u666f\uff09"},"content":{"rendered":"<h1 id=\"%e5%80%9f%e5%8a%a9redis%e5%af%a6%e7%8f%be%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e7%9a%84%e6%a7%8b%e5%bb%ba%e4%b9%8b%e9%81%93-WBtAdUYdfC\">\u501f\u52a9Redis\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u7684\u69cb\u5efa\u4e4b\u9053<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u61c9\u7528\u4e2d\uff0c\u6578\u64da\u7684\u8b80\u53d6\u548c\u5beb\u5165\u64cd\u4f5c\u662f\u6700\u57fa\u672c\u7684\u9700\u6c42\u3002\u96a8\u8457\u7528\u6236\u6578\u91cf\u7684\u589e\u52a0\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u8655\u7406\u9019\u4e9b\u64cd\u4f5c\u6210\u70ba\u4e86\u958b\u767c\u8005\u9762\u81e8\u7684\u4e00\u5927\u6311\u6230\u3002Redis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5167\u5b58\u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u529f\u80fd\u4f86\u652f\u6301\u8b80\u5beb\u5206\u96e2\u7684\u67b6\u69cb\uff0c\u5f9e\u800c\u63d0\u5347\u7cfb\u7d71\u7684\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%ef%bc%9f-WBtAdUYdfC\">\u4ec0\u9ebc\u662f\u8b80\u5beb\u5206\u96e2\uff1f<\/h2>\n<p>\u8b80\u5beb\u5206\u96e2\u662f\u4e00\u7a2e\u5c07\u6578\u64da\u5eab\u7684\u8b80\u53d6\u64cd\u4f5c\u548c\u5beb\u5165\u64cd\u4f5c\u5206\u958b\u8655\u7406\u7684\u67b6\u69cb\u8a2d\u8a08\u3002\u9019\u7a2e\u8a2d\u8a08\u7684\u4e3b\u8981\u76ee\u7684\u662f\u6e1b\u5c11\u4e3b\u6578\u64da\u5eab\u7684\u8ca0\u64d4\uff0c\u63d0\u5347\u6574\u9ad4\u7cfb\u7d71\u7684\u6027\u80fd\u3002\u901a\u5e38\uff0c\u4e3b\u6578\u64da\u5eab\u8ca0\u8cac\u5beb\u5165\u64cd\u4f5c\uff0c\u800c\u5f9e\u6578\u64da\u5eab\u5247\u5c08\u6ce8\u65bc\u8b80\u53d6\u64cd\u4f5c\u3002\u9019\u6a23\u7684\u67b6\u69cb\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u9ad8\u6578\u64da\u7684\u8b80\u53d6\u901f\u5ea6\uff0c\u4e26\u4e14\u5728\u9ad8\u4e26\u767c\u7684\u60c5\u6cc1\u4e0b\uff0c\u80fd\u5920\u66f4\u597d\u5730\u61c9\u5c0d\u6d41\u91cf\u7684\u6fc0\u589e\u3002<\/p>\n<h2 id=\"redis%e5%9c%a8%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e4%b8%ad%e7%9a%84%e8%a7%92%e8%89%b2-WBtAdUYdfC\">Redis\u5728\u8b80\u5beb\u5206\u96e2\u4e2d\u7684\u89d2\u8272<\/h2>\n<p>Redis\u4f5c\u70ba\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u80fd\u5920\u5728\u8b80\u5beb\u5206\u96e2\u7684\u67b6\u69cb\u4e2d\u767c\u63ee\u91cd\u8981\u4f5c\u7528\u3002\u5b83\u53ef\u4ee5\u4f5c\u70ba\u5f9e\u6578\u64da\u5eab\uff0c\u5c08\u9580\u8655\u7406\u8b80\u53d6\u8acb\u6c42\uff0c\u800c\u4e3b\u6578\u64da\u5eab\u5247\u5c08\u6ce8\u65bc\u5beb\u5165\u64cd\u4f5c\u3002\u9019\u6a23\u7684\u8a2d\u8a08\u4e0d\u50c5\u80fd\u5920\u63d0\u9ad8\u8b80\u53d6\u6548\u7387\uff0c\u9084\u80fd\u6e1b\u5c11\u4e3b\u6578\u64da\u5eab\u7684\u58d3\u529b\u3002<\/p>\n<h3 id=\"%e5%af%a6%e7%8f%be%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%ad%a5%e9%a9%9f-WBtAdUYdfC\">\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u7684\u57fa\u672c\u6b65\u9a5f<\/h3>\n<ul>\n<li><strong>\u8a2d\u7f6e\u4e3b\u5f9e\u6578\u64da\u5eab\uff1a<\/strong>\u9996\u5148\uff0c\u9700\u8981\u8a2d\u7f6e\u4e00\u500b\u4e3b\u6578\u64da\u5eab\u548c\u4e00\u500b\u6216\u591a\u500b\u5f9e\u6578\u64da\u5eab\u3002\u4e3b\u6578\u64da\u5eab\u8ca0\u8cac\u6240\u6709\u7684\u5beb\u5165\u64cd\u4f5c\uff0c\u800c\u5f9e\u6578\u64da\u5eab\u5247\u7528\u65bc\u8b80\u53d6\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u914d\u7f6eRedis\uff1a<\/strong>\u5728Redis\u4e2d\uff0c\u53ef\u4ee5\u901a\u904e\u914d\u7f6e\u4e3b\u5f9e\u8907\u88fd\u4f86\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u3002\u4e3bRedis\u5be6\u4f8b\u8ca0\u8cac\u5beb\u5165\uff0c\u800c\u5f9eRedis\u5be6\u4f8b\u5247\u81ea\u52d5\u5f9e\u4e3b\u5be6\u4f8b\u4e2d\u7372\u53d6\u6578\u64da\u3002<\/li>\n<li><strong>\u61c9\u7528\u5c64\u908f\u8f2f\uff1a<\/strong>\u5728\u61c9\u7528\u5c64\u4e2d\uff0c\u9700\u8981\u6839\u64da\u64cd\u4f5c\u985e\u578b\u4f86\u9078\u64c7\u4f7f\u7528\u4e3b\u6578\u64da\u5eab\u9084\u662f\u5f9e\u6578\u64da\u5eab\u3002\u901a\u5e38\uff0c\u5beb\u5165\u64cd\u4f5c\u6703\u767c\u9001\u5230\u4e3b\u6578\u64da\u5eab\uff0c\u800c\u8b80\u53d6\u64cd\u4f5c\u5247\u767c\u9001\u5230\u5f9e\u6578\u64da\u5eab\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a2%bc-WBtAdUYdfC\">\u793a\u4f8b\u4ee3\u78bc<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728Node.js\u4e2d\u5be6\u73feRedis\u7684\u8b80\u5beb\u5206\u96e2\uff1a<\/p>\n<pre><code>\nconst redis = require('redis');\n\n\/\/ \u5275\u5efa\u4e3bRedis\u5ba2\u6236\u7aef\nconst masterClient = redis.createClient({\n    host: '\u4e3b\u6578\u64da\u5eab\u5730\u5740',\n    port: 6379\n});\n\n\/\/ \u5275\u5efa\u5f9eRedis\u5ba2\u6236\u7aef\nconst slaveClient = redis.createClient({\n    host: '\u5f9e\u6578\u64da\u5eab\u5730\u5740',\n    port: 6379\n});\n\n\/\/ \u5beb\u5165\u6578\u64da\u5230\u4e3b\u6578\u64da\u5eab\nmasterClient.set('key', 'value', (err, reply) =&gt; {\n    if (err) {\n        console.error('\u5beb\u5165\u932f\u8aa4:', err);\n    } else {\n        console.log('\u5beb\u5165\u6210\u529f:', reply);\n    }\n});\n\n\/\/ \u5f9e\u5f9e\u6578\u64da\u5eab\u8b80\u53d6\u6578\u64da\nslaveClient.get('key', (err, reply) =&gt; {\n    if (err) {\n        console.error('\u8b80\u53d6\u932f\u8aa4:', err);\n    } else {\n        console.log('\u8b80\u53d6\u7d50\u679c:', reply);\n    }\n});\n<\/code><\/pre>\n<h2 id=\"%e5%84%aa%e5%8b%a2%e8%88%87%e6%8c%91%e6%88%b0-WBtAdUYdfC\">\u512a\u52e2\u8207\u6311\u6230<\/h2>\n<p>\u4f7f\u7528Redis\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u6709\u591a\u500b\u512a\u52e2\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u63d0\u5347\uff1a<\/strong>\u901a\u904e\u5c07\u8b80\u53d6\u8acb\u6c42\u5206\u6563\u5230\u591a\u500b\u5f9e\u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u7cfb\u7d71\u7684\u8b80\u53d6\u6027\u80fd\u3002<\/li>\n<li><strong>\u53ef\u64f4\u5c55\u6027\uff1a<\/strong>\u96a8\u8457\u7528\u6236\u6578\u91cf\u7684\u589e\u52a0\uff0c\u53ef\u4ee5\u8f15\u9b06\u5730\u6dfb\u52a0\u66f4\u591a\u7684\u5f9e\u6578\u64da\u5eab\u4f86\u61c9\u5c0d\u6d41\u91cf\u7684\u589e\u9577\u3002<\/li>\n<li><strong>\u964d\u4f4e\u4e3b\u6578\u64da\u5eab\u58d3\u529b\uff1a<\/strong>\u4e3b\u6578\u64da\u5eab\u53ea\u9700\u8655\u7406\u5beb\u5165\u8acb\u6c42\uff0c\u5f9e\u800c\u6e1b\u5c11\u4e86\u5176\u8ca0\u64d4\u3002<\/li>\n<\/ul>\n<p>\u7136\u800c\uff0c\u9019\u7a2e\u67b6\u69cb\u4e5f\u9762\u81e8\u4e00\u4e9b\u6311\u6230\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u4e00\u81f4\u6027\uff1a<\/strong>\u7531\u65bc\u5f9e\u6578\u64da\u5eab\u662f\u5f9e\u4e3b\u6578\u64da\u5eab\u8907\u88fd\u6578\u64da\uff0c\u53ef\u80fd\u6703\u51fa\u73fe\u77ed\u66ab\u7684\u4e0d\u4e00\u81f4\u6027\u3002<\/li>\n<li><strong>\u8907\u96dc\u6027\u589e\u52a0\uff1a<\/strong>\u9700\u8981\u5728\u61c9\u7528\u5c64\u4e2d\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u7684\u908f\u8f2f\uff0c\u589e\u52a0\u4e86\u7cfb\u7d71\u7684\u8907\u96dc\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-WBtAdUYdfC\">\u7e3d\u7d50<\/h2>\n<p>\u501f\u52a9Redis\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u662f\u4e00\u7a2e\u6709\u6548\u7684\u67b6\u69cb\u8a2d\u8a08\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u5347\u7cfb\u7d71\u7684\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e\u4e3b\u5f9e\u6578\u64da\u5eab\uff0c\u4e26\u5728\u61c9\u7528\u5c64\u4e2d\u5be6\u73fe\u76f8\u61c9\u7684\u908f\u8f2f\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u61c9\u5c0d\u9ad8\u4e26\u767c\u7684\u8b80\u53d6\u9700\u6c42\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u548c\u9ad8\u53ef\u7528\u6027\u7684\u61c9\u7528\u4f86\u8aaa\uff0c\u9019\u7a2e\u67b6\u69cb\u7121\u7591\u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002\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\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u69cb\u5efa\u7a69\u5b9a\u7684\u61c9\u7528\u74b0\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5229\u7528Redis\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\uff0c\u63d0\u5347\u7cfb\u7d71\u6027\u80fd\u8207\u64f4\u5c55\u6027\uff0c\u9069\u7528\u65bc\u9ad8\u6548\u80fd\u6578\u64da\u8655\u7406\u5834\u666f\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-164187","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/164187","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=164187"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/164187\/revisions"}],"predecessor-version":[{"id":164188,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/164187\/revisions\/164188"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=164187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=164187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=164187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}