{"id":6275,"date":"2024-11-14T13:46:04","date_gmt":"2024-11-14T05:46:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6275\/"},"modified":"2024-11-14T13:46:04","modified_gmt":"2024-11-14T05:46:04","slug":"redis%e6%80%8e%e6%a0%b7%e8%bf%9e%e6%8e%a5redisclient","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6275\/","title":{"rendered":"redis\u600e\u6837\u8fde\u63a5redisclient"},"content":{"rendered":"<p><strong>client \u4e0e redis \u7684\u8fde\u63a5\u65b9\u5f0f<\/strong><\/p>\n<p>\u8fde\u63a5 RedisClient \u548c Redis \u6570\u636e\u5e93\u4e3b\u8981\u6709\u4e09\u79cd\u65b9\u5f0f\uff1a<\/p>\n<p><strong>1. \u76f4\u63a5\u8fde\u63a5<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u662f\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528 RedisClient \u7c7b\u6765\u521b\u5efa\u5bf9 Redis \u6570\u636e\u5e93\u7684\u8fde\u63a5\uff1a<\/p>\n<pre>var redis = new RedisClient(\"localhost\", 6379);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0c&#8221;localhost&#8221; \u662f Redis \u6570\u636e\u5e93\u7684\u4e3b\u673a\u5730\u5740\uff0c6379 \u662f Redis \u9ed8\u8ba4\u7aef\u53e3\u3002<\/p>\n<p><strong>2. \u4f7f\u7528\u8fde\u63a5\u5b57\u7b26\u4e32<\/strong><\/p>\n<p>\u5982\u679c\u4e0d\u60f3\u76f4\u63a5\u6307\u5b9a\u4e3b\u673a\u548c\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fde\u63a5\u5b57\u7b26\u4e32\u6765\u8fdb\u884c\u8fde\u63a5\uff1a<\/p>\n<pre>var connectionString = \"localhost:6379\";\nvar redis = new RedisClient(connectionString);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fde\u63a5\u5b57\u7b26\u4e32\u53ef\u4ee5\u5305\u542b\u4e3b\u673a\u5730\u5740\u3001\u7aef\u53e3\u3001\u5bc6\u7801\u548c\u6570\u636e\u5e93\u7d22\u5f15\u7b49\u4fe1\u606f\u3002<\/p>\n<p><strong>3. \u4f7f\u7528\u8fde\u63a5\u6c60<\/strong><\/p>\n<p>\u8fde\u63a5\u6c60\u53ef\u4ee5\u63d0\u9ad8\u8fde\u63a5\u6548\u7387\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u7684\u573a\u666f\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u8fde\u63a5\u6c60\u521b\u5efa RedisClient \u8fde\u63a5\uff1a<\/p>\n<pre>var pool = new RedisClientPool(\"localhost:6379\");\nvar redis = pool.GetClient();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u5b8c\u6bd5\u540e\uff0c\u8bb0\u5f97\u91ca\u653e\u8fde\u63a5\uff1a<\/p>\n<pre>pool.Return(redis);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>RedisClient \u7c7b\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5ba2\u6237\u7aef\u5e93\uff0c\u5b83\u5728\u5185\u90e8\u4f7f\u7528 TCP \u534f\u8bae\u4e0e Redis \u6570\u636e\u5e93\u8fdb\u884c\u901a\u4fe1\u3002<\/li>\n<li>\u9700\u8981\u786e\u4fdd Redis \u6570\u636e\u5e93\u6b63\u5728\u8fd0\u884c\uff0c\u5e76\u4e14\u53ef\u4ee5\u8bbf\u95ee\u3002<\/li>\n<li>\u8fde\u63a5 Redis \u6570\u636e\u5e93\u65f6\uff0c\u5982\u679c\u9700\u8981\u5bc6\u7801\u8ba4\u8bc1\uff0c\u8bf7\u4f7f\u7528 Connect() \u65b9\u6cd5\uff1a<\/li>\n<\/ul>\n<pre>redis.Connect(\"password\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u6837\u8fde\u63a5redisclient\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>client \u4e0e redis \u7684\u8fde\u63a5\u65b9\u5f0f \u8fde\u63a5 RedisClient \u548c Redis \u6570\u636e\u5e93\u4e3b\u8981\u6709\u4e09\u79cd\u65b9\u5f0f\uff1a 1. \u76f4\u63a5\u8fde\u63a5 \u6700\u7b80\u5355\u7684\u65b9\u5f0f\u662f\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528 RedisClient \u7c7b\u6765\u521b\u5efa\u5bf9 Redis \u6570\u636e\u5e93\u7684\u8fde\u63a5\uff1a var redis = new RedisClient(&#8220;localhost&#8221;, 6379); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0c&#8221;localhost&#8221; \u662f Redis \u6570\u636e\u5e93\u7684\u4e3b\u673a\u5730\u5740\uff0c6379 \u662f Redis \u9ed8\u8ba4\u7aef\u53e3\u3002 2. \u4f7f\u7528\u8fde\u63a5\u5b57\u7b26\u4e32 \u5982\u679c\u4e0d\u60f3\u76f4\u63a5\u6307\u5b9a\u4e3b\u673a\u548c\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fde\u63a5\u5b57\u7b26\u4e32\u6765\u8fdb\u884c\u8fde\u63a5\uff1a var connectionString = &#8220;localhost:6379&#8221;; var redis = new RedisClient(connectionString); \u767b\u5f55\u540e\u590d\u5236 \u8fde\u63a5\u5b57\u7b26\u4e32\u53ef\u4ee5\u5305\u542b\u4e3b\u673a\u5730\u5740\u3001\u7aef\u53e3\u3001\u5bc6\u7801\u548c\u6570\u636e\u5e93\u7d22\u5f15\u7b49\u4fe1\u606f\u3002 3. \u4f7f\u7528\u8fde\u63a5\u6c60 \u8fde\u63a5\u6c60\u53ef\u4ee5\u63d0\u9ad8\u8fde\u63a5\u6548\u7387\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u7684\u573a\u666f\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u8fde\u63a5\u6c60\u521b\u5efa RedisClient \u8fde\u63a5\uff1a var pool = new RedisClientPool(&#8220;localhost:6379&#8221;); var [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6275","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6275"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6275\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}