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

关于Redis的订阅(subscribe)问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:43:05
Original
1242 people have browsed it

<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>
Copy after login
Copy after login

上面这段代码为什么回调函数里面执行任何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>
Copy after login
Copy after login

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

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

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template