作者 karlet

feat:readtimeout

@@ -15,6 +15,7 @@ class RedisCli @@ -15,6 +15,7 @@ class RedisCli
15 ->withAuth($password) 15 ->withAuth($password)
16 ->withDbIndex($dbIndex) 16 ->withDbIndex($dbIndex)
17 ->withTimeout($timeout) 17 ->withTimeout($timeout)
  18 + ->withReadTimeout($timeout)
18 ,$num //默认64个连接池 19 ,$num //默认64个连接池
19 ); 20 );
20 } 21 }
@@ -129,4 +130,18 @@ class RedisCli @@ -129,4 +130,18 @@ class RedisCli
129 return $res; 130 return $res;
130 } 131 }
131 132
  133 + public function psubscribe($channels,callable $onMessage)
  134 + {
  135 + $redis = $this->pool->get();
  136 + try {
  137 + $res = $redis->psubscribe($channels,function($redis, $pattern, $channel, $message)use($onMessage){
  138 + call_user_func($onMessage, $pattern, $redis, $channel, $message);
  139 + });
  140 + }catch (\RedisException $e) {
  141 + return false;
  142 + }
  143 + $this->pool->put($redis);
  144 + return $res;
  145 + }
  146 +
132 } 147 }