Home >Backend Development >PHP Tutorial >关于Redis的订阅(subscribe)问题

关于Redis的订阅(subscribe)问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:43:051237browse

<code><?php $redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->setOption(\Redis::OPT_READ_TIMEOUT, -1);
$redis->subscribe(['testChannel'], 'parse');
function parse($redis, $channel, $message) {
        var_dump($redis->keys('*'));
}

?>
</code>

上面这段代码为什么回调函数里面执行任何redis的接口操作都是返回false啊,求大神指导。谢谢。

回复内容:

<code><?php $redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->setOption(\Redis::OPT_READ_TIMEOUT, -1);
$redis->subscribe(['testChannel'], 'parse');
function parse($redis, $channel, $message) {
        var_dump($redis->keys('*'));
}

?>
</code>

上面这段代码为什么回调函数里面执行任何redis的接口操作都是返回false啊,求大神指导。谢谢。

在Redis中,一旦一个client发出了SUBSCRIBE命令,它就处于监听的模式,此时除了SUBSCRIBEPSUBSCRIBEUNSUBSCRIBEPUNSUBSCRIBE这4条命令之外的所有其它命令都不能用。
文档里写得很清楚嘛。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn