Home > Backend Development > PHP Tutorial > PHP redis 订阅发布 订阅不成功问题!

PHP redis 订阅发布 订阅不成功问题!

WBOY
Release: 2016-06-20 12:50:16
Original
1871 people have browsed it

我当前的是可以发布的,但是订阅不行,新手求解!

发布正常
    $redis = new Redis();      $redis->connect("127.0.0.1","6379");     $redis->publish('tv1', '22222222'); //发布
Copy after login


接收如下:


订阅 ,页面一直在转圈,没有返回任何信息。
       $channel = 'tv1';  // channel	$redis->subscribe(array('channel'.$channel), 'callback');	function callback($redis, $channel, $message) {	  var_dump($message);	  exit;	}
Copy after login







第一次使用Redis 发布订阅,求大神帮忙看下!



回复讨论(解决方案)

正确写法


    $channel = 'tv1';  // channel    $redis->subscribe(array($channel), 'callback');    function callback($redis, $channel, $message) {      var_dump($message);      exit;    }
Copy after login


 $redis->subscribe(array( 'channel'.$channel), 'callback');

直接去掉 红色部分就行了,搞了二天的问题。

是我太粗心了,才导致这样的错误。

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template