订阅
<?php
$redis = new Redis();
$redis->pconnect("127.0.0.1",6379);
$redis->auth("243356");
$redis->setOption(Redis::OPT_READ_TIMEOUT,-1);
$redis->subscribe(array('news'),'callback');
function callback($instance,$channelName,$message){
echo $channelName,"==>",json_decode($message)->msg,PHP_EOL;
}
发布
<?php
$redis = new Redis();
$redis->connect("127.0.0.1",6379);
$redis->auth("243356");
$redis->publish('news',json_encode(array('news','msg'=>"Hello world")));