{"id":48572,"date":"2024-12-02T15:01:17","date_gmt":"2024-12-02T07:01:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48572\/"},"modified":"2024-12-02T15:01:17","modified_gmt":"2024-12-02T07:01:17","slug":"%e4%bd%bf%e7%94%a8-workerman-%e5%92%8c-predis-%e8%bf%9e%e6%8e%a5-redis-%e5%87%ba%e7%8e%b0%e6%96%ad%e5%bc%80%e9%97%ae%e9%a2%98%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48572\/","title":{"rendered":"## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300a## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730088770671f0f425aae2.jpg\" class=\"aligncenter\" title=\"## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php workerman \u4f7f\u7528predis \u5728\u547d\u4ee4\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\u5c31\u65ad\u5f00\u4e86<\/strong><\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0\uff1a<\/strong><br \/>\u4f7f\u7528 php workerman \u7ed3\u5408 predis \u64cd\u4f5c redis \u670d\u52a1\u65f6\uff0c\u4e00\u6bb5\u65f6\u95f4\u540e\u51fa\u73b0\u65ad\u5f00\u7684\u9519\u8bef\uff1aerror while reading line from the server\u3002\u8fd0\u884c\u7684\u8fdb\u7a0b\u4e5f\u7ec8\u6b62\u3002<\/p>\n<p><strong>\u4ee3\u7801\u6bb5\uff1a<\/strong><\/p>\n<pre>use predis\\client;\n\nclass redisservice {\n  public $handler;\n\n  public function __construct() {\n    $this-&gt;handler = new client(self::get_servers());\n  }\n\n  private static function get_servers() {\n    return ['tcp:\/\/127.0.0.1:6379'];\n  }\n\n  public function get($name) {\n    $value = $this-&gt;handler-&gt;get($name);\n    return json_decode($value, true);\n  }\n}<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><br \/>\u8bbe\u7f6e read_write_timeout \u4e3a 0 \u6216 -1\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>$redis = new Predis\\Client('tcp:\/\/10.0.0.1:6379?read_write_timeout=0');<\/pre>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><br \/>read_write_timeout \u9009\u9879\u6307\u5b9a\u4e86\u5728\u670d\u52a1\u5668\u4e0a\u8bfb\u53d6\u6216\u5199\u5165\u64cd\u4f5c\u5141\u8bb8\u7684\u7a7a\u95f2\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002\u5c06\u6b64\u9009\u9879\u8bbe\u7f6e\u4e3a 0 \u6216 -1 \u8868\u793a\u65e0\u8d85\u65f6\u9650\u5236\u3002\u8fd9\u53ef\u4ee5\u89e3\u51b3\u4e00\u6bb5\u65f6\u95f4\u540e redis \u670d\u52a1\u5668\u65ad\u5f00\u8fde\u63a5\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f \u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300a## \u4f7f\u7528 Workerman \u548c Predis \u8fde\u63a5 Redis \u51fa\u73b0\u65ad\u5f00\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002 php workerman \u4f7f\u7528predis \u5728\u547d\u4ee4\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\u5c31\u65ad\u5f00\u4e86 \u95ee\u9898\u63cf\u8ff0\uff1a\u4f7f\u7528 php workerman \u7ed3\u5408 predis \u64cd\u4f5c redis \u670d\u52a1\u65f6\uff0c\u4e00\u6bb5\u65f6\u95f4\u540e\u51fa\u73b0\u65ad\u5f00\u7684\u9519\u8bef\uff1aerror while reading line from the server\u3002\u8fd0\u884c\u7684\u8fdb\u7a0b\u4e5f\u7ec8\u6b62\u3002 \u4ee3\u7801\u6bb5\uff1a use predis\\client; class redisservice { public $handler; public function __construct() { $this-&gt;handler = new client(self::get_servers()); } private static function get_servers() [&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-48572","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48572","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=48572"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48572\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}