正在显示
1 个修改的文件
包含
5 行增加
和
0 行删除
| @@ -7,6 +7,7 @@ use Swoole\Database\RedisPool; | @@ -7,6 +7,7 @@ use Swoole\Database\RedisPool; | ||
| 7 | class RedisCli | 7 | class RedisCli |
| 8 | { | 8 | { |
| 9 | private $pool; | 9 | private $pool; |
| 10 | + public $subRedis = null; | ||
| 10 | public function __construct($host,$port,$password,$dbIndex, $num = 20) | 11 | public function __construct($host,$port,$password,$dbIndex, $num = 20) |
| 11 | { | 12 | { |
| 12 | $this->pool = new RedisPool((new RedisConfig) | 13 | $this->pool = new RedisPool((new RedisConfig) |
| @@ -117,6 +118,7 @@ class RedisCli | @@ -117,6 +118,7 @@ class RedisCli | ||
| 117 | public function subscribe($channels,callable $onMessage) | 118 | public function subscribe($channels,callable $onMessage) |
| 118 | { | 119 | { |
| 119 | $redis = $this->pool->get(); | 120 | $redis = $this->pool->get(); |
| 121 | + $this->subRedis = $redis; | ||
| 120 | try { | 122 | try { |
| 121 | $res = $redis->subscribe($channels,function($redis, $channel, $message)use($onMessage){ | 123 | $res = $redis->subscribe($channels,function($redis, $channel, $message)use($onMessage){ |
| 122 | call_user_func($onMessage,$redis, $channel, $message); | 124 | call_user_func($onMessage,$redis, $channel, $message); |
| @@ -124,6 +126,7 @@ class RedisCli | @@ -124,6 +126,7 @@ class RedisCli | ||
| 124 | } catch (\RedisException $e) { | 126 | } catch (\RedisException $e) { |
| 125 | return false; | 127 | return false; |
| 126 | } | 128 | } |
| 129 | + $this->subRedis = null; | ||
| 127 | $this->pool->put($redis); | 130 | $this->pool->put($redis); |
| 128 | return $res; | 131 | return $res; |
| 129 | } | 132 | } |
| @@ -131,6 +134,7 @@ class RedisCli | @@ -131,6 +134,7 @@ class RedisCli | ||
| 131 | public function psubscribe($channels,callable $onMessage) | 134 | public function psubscribe($channels,callable $onMessage) |
| 132 | { | 135 | { |
| 133 | $redis = $this->pool->get(); | 136 | $redis = $this->pool->get(); |
| 137 | + $this->subRedis = $redis; | ||
| 134 | try { | 138 | try { |
| 135 | $res = $redis->psubscribe($channels,function($redis, $pattern, $channel, $message)use($onMessage){ | 139 | $res = $redis->psubscribe($channels,function($redis, $pattern, $channel, $message)use($onMessage){ |
| 136 | call_user_func($onMessage, $pattern, $redis, $channel, $message); | 140 | call_user_func($onMessage, $pattern, $redis, $channel, $message); |
| @@ -138,6 +142,7 @@ class RedisCli | @@ -138,6 +142,7 @@ class RedisCli | ||
| 138 | }catch (\RedisException $e) { | 142 | }catch (\RedisException $e) { |
| 139 | return false; | 143 | return false; |
| 140 | } | 144 | } |
| 145 | + $this->subRedis = null; | ||
| 141 | $this->pool->put($redis); | 146 | $this->pool->put($redis); |
| 142 | return $res; | 147 | return $res; |
| 143 | } | 148 | } |
-
请 注册 或 登录 后发表评论