laravel Redis扩展 发布订阅是不是有bug呀
出现的问题:在使用psubscribe或者subscribe的时候不能设置redis字符串的使用
我的代码
Redis::psubscribe(['test*'], function ($message, $channel) {
Redis::set($channel, $message); // 这一句没有效果
if ($channel == 'test-channel') {
echo 'test-channel';
} else {
echo $channel . ':' . $message;
}
});
Redis源码:
/**
* Subscribe to a set of given channels with wildcards. * * @param array|string $channels
* @param \Closure $callback
* @return void
*/public function psubscribe($channels, Closure $callback)
{
$this->client->psubscribe((array) $channels, function ($redis, $pattern, $channel, $message) use ($callback) {
$callback($message, $channel);
});
}
/**
* Subscribe to a set of given channels for messages. * * @param array|string $channels
* @param \Closure $callback
* @return void
*/public function subscribe($channels, Closure $callback)
{
$this->client->subscribe((array) $channels, function ($redis, $channel, $message) use ($callback) {
$callback($message, $channel);
});
}
当中第二个参数闭包不能使用$redis
接收消息的回调函数。除了SUBSCRIBE、PSUBSCRIBE、UNSUBSCRIBE、PUNSUBSCRIBE这4条命令以外,其它命令都不能使用。
segmentfault.com/a/119000001028736...