{"id":126047,"date":"2024-10-26T01:27:20","date_gmt":"2024-10-25T17:27:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/126047\/"},"modified":"2024-10-26T01:27:21","modified_gmt":"2024-10-25T17:27:21","slug":"redis-%e9%80%a3%e6%8e%a5%e6%b7%b1%e5%ba%a6%e5%89%96%e6%9e%90","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/126047\/","title":{"rendered":"Redis \u9023\u63a5\u6df1\u5ea6\u5256\u6790"},"content":{"rendered":"<h1 id=\"redis-%e9%80%a3%e6%8e%a5%e6%b7%b1%e5%ba%a6%e5%89%96%e6%9e%90-rkkOpsAOsc\">Redis \u9023\u63a5\u6df1\u5ea6\u5256\u6790<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0cRedis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5df2\u7d93\u6210\u70ba\u8a31\u591a\u61c9\u7528\u7a0b\u5e8f\u7684\u6838\u5fc3\u7d44\u4ef6\u3002\u7121\u8ad6\u662f\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u9084\u662f\u6578\u64da\u6301\u4e45\u5316\uff0cRedis \u90fd\u4ee5\u5176\u5353\u8d8a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u6027\u8d0f\u5f97\u4e86\u958b\u767c\u8005\u7684\u9752\u775e\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Redis \u7684\u9023\u63a5\u6a5f\u5236\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u53ca\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2 id=\"redis-%e9%80%a3%e6%8e%a5%e6%a6%82%e8%bf%b0-rkkOpsAOsc\">Redis \u9023\u63a5\u6982\u8ff0<\/h2>\n<p>Redis \u4f7f\u7528 TCP \u5354\u8b70\u9032\u884c\u5ba2\u6236\u7aef\u548c\u670d\u52d9\u5668\u4e4b\u9593\u7684\u901a\u4fe1\u3002\u6bcf\u7576\u5ba2\u6236\u7aef\u9700\u8981\u8207 Redis \u670d\u52d9\u5668\u4ea4\u4e92\u6642\uff0c\u9996\u5148\u9700\u8981\u5efa\u7acb\u4e00\u500b TCP \u9023\u63a5\u3002\u9019\u500b\u904e\u7a0b\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u5ba2\u6236\u7aef\u767c\u8d77\u9023\u63a5\u8acb\u6c42\u3002<\/li>\n<li>\u670d\u52d9\u5668\u63a5\u53d7\u8acb\u6c42\u4e26\u5efa\u7acb\u9023\u63a5\u3002<\/li>\n<li>\u96d9\u65b9\u9032\u884c\u6578\u64da\u4ea4\u63db\u3002<\/li>\n<\/ul>\n<h2 id=\"%e9%80%a3%e6%8e%a5%e7%9a%84%e5%bb%ba%e7%ab%8b-rkkOpsAOsc\">\u9023\u63a5\u7684\u5efa\u7acb<\/h2>\n<p>\u5728 Redis \u4e2d\uff0c\u9023\u63a5\u7684\u5efa\u7acb\u662f\u901a\u904e\u4ee5\u4e0b\u65b9\u5f0f\u9032\u884c\u7684\uff1a<\/p>\n<pre><code>redis-cli -h  -p <\/code><\/pre>\n<p>\u9019\u88e1\uff0c<code><\/code> \u662f Redis \u670d\u52d9\u5668\u7684\u5730\u5740\uff0c<code><\/code> \u662f Redis \u670d\u52d9\u5668\u7684\u7aef\u53e3\uff08\u9ed8\u8a8d\u70ba 6379\uff09\u3002\u4e00\u65e6\u9023\u63a5\u6210\u529f\uff0c\u5ba2\u6236\u7aef\u5c31\u53ef\u4ee5\u767c\u9001\u547d\u4ee4\u4f86\u64cd\u4f5c\u6578\u64da\u3002<\/p>\n<h2 id=\"%e9%80%a3%e6%8e%a5%e7%9a%84%e7%ae%a1%e7%90%86-rkkOpsAOsc\">\u9023\u63a5\u7684\u7ba1\u7406<\/h2>\n<p>Redis \u63d0\u4f9b\u4e86\u591a\u7a2e\u65b9\u5f0f\u4f86\u7ba1\u7406\u9023\u63a5\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u6301\u4e45\u9023\u63a5\uff1a<\/strong>\u5ba2\u6236\u7aef\u53ef\u4ee5\u9078\u64c7\u4fdd\u6301\u9023\u63a5\u6301\u4e45\u5316\uff0c\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u6bcf\u6b21\u8acb\u6c42\u7684\u5ef6\u9072\u3002<\/li>\n<li><strong>\u9023\u63a5\u6c60\uff1a<\/strong>\u4f7f\u7528\u9023\u63a5\u6c60\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u591a\u500b\u9023\u63a5\uff0c\u7279\u5225\u662f\u5728\u9ad8\u4f75\u767c\u7684\u60c5\u6cc1\u4e0b\uff0c\u9019\u6a23\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h3 id=\"%e6%8c%81%e4%b9%85%e9%80%a3%e6%8e%a5%e7%a4%ba%e4%be%8b-rkkOpsAOsc\">\u6301\u4e45\u9023\u63a5\u793a\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528\u6301\u4e45\u9023\u63a5\u7684\u7c21\u55ae\u793a\u4f8b\uff1a<\/p>\n<pre><code>const redis = require('redis');\nconst client = redis.createClient({\n    host: '',\n    port: ,\n    no_ready_check: true\n});\n\nclient.on('connect', function() {\n    console.log('Connected to Redis...');\n});\n<\/code><\/pre>\n<h3 id=\"%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%a4%ba%e4%be%8b-rkkOpsAOsc\">\u9023\u63a5\u6c60\u793a\u4f8b<\/h3>\n<p>\u4f7f\u7528\u9023\u63a5\u6c60\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>const genericPool = require('generic-pool');\nconst redis = require('redis');\n\nconst factory = {\n    create: function() {\n        return new Promise(function(resolve, reject) {\n            const client = redis.createClient();\n            client.on('connect', () =&gt; resolve(client));\n            client.on('error', (err) =&gt; reject(err));\n        });\n    },\n    destroy: function(client) {\n        return new Promise(function(resolve) {\n            client.quit();\n            resolve();\n        });\n    }\n};\n\nconst pool = genericPool.createPool(factory, { max: 10, min: 2 });\n<\/code><\/pre>\n<h2 id=\"%e9%80%a3%e6%8e%a5%e7%9a%84%e6%80%a7%e8%83%bd%e8%80%83%e9%87%8f-rkkOpsAOsc\">\u9023\u63a5\u7684\u6027\u80fd\u8003\u91cf<\/h2>\n<p>\u5728\u4f7f\u7528 Redis \u6642\uff0c\u9023\u63a5\u7684\u6027\u80fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\uff1a<\/p>\n<ul>\n<li>\u907f\u514d\u983b\u7e41\u5efa\u7acb\u548c\u95dc\u9589\u9023\u63a5\uff0c\u61c9\u4f7f\u7528\u6301\u4e45\u9023\u63a5\u6216\u9023\u63a5\u6c60\u3002<\/li>\n<li>\u6839\u64da\u61c9\u7528\u9700\u6c42\u8abf\u6574\u6700\u5927\u9023\u63a5\u6578\uff0c\u4ee5\u9632\u6b62\u8cc7\u6e90\u6d6a\u8cbb\u3002<\/li>\n<li>\u76e3\u63a7\u9023\u63a5\u7684\u5065\u5eb7\u72c0\u614b\uff0c\u53ca\u6642\u8655\u7406\u7570\u5e38\u60c5\u6cc1\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-rkkOpsAOsc\">\u7d50\u8ad6<\/h2>\n<p>Redis \u7684\u9023\u63a5\u6a5f\u5236\u662f\u5176\u9ad8\u6548\u6027\u80fd\u7684\u57fa\u790e\u3002\u901a\u904e\u5408\u7406\u7684\u9023\u63a5\u7ba1\u7406\u548c\u6027\u80fd\u512a\u5316\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5145\u5206\u767c\u63ee Redis \u7684\u6f5b\u529b\uff0c\u63d0\u5347\u61c9\u7528\u7684\u6574\u9ad4\u6027\u80fd\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u5b58\u53d6\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684\u9023\u63a5\u7b56\u7565\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">VPS<\/a> \u53ca\u5176\u5728 Redis \u61c9\u7528\u4e2d\u7684\u512a\u52e2\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u5256\u6790Redis\u9023\u63a5\uff0c\u63a2\u7d22\u5176\u67b6\u69cb\u3001\u6027\u80fd\u512a\u5316\u53ca\u6700\u4f73\u5be6\u8e10\uff0c\u52a9\u60a8\u63d0\u5347\u6578\u64da\u5b58\u53d6\u6548\u7387\u8207\u61c9\u7528\u8868\u73fe\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-126047","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/126047","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=126047"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/126047\/revisions"}],"predecessor-version":[{"id":126048,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/126047\/revisions\/126048"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=126047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=126047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=126047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}