订阅
<?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); $channel = $argv[1]; // channel $redis->subscribe(array('channel'.$channel), 'callback'); function callback($instance, $channelName, $message) { echo $channelName, "==>", $message,PHP_EOL; }
发布
<?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); $channel = $argv[1]; // channel $msg = $argv[2]; // msg $redis->publish('channel'.$channel, $msg);
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。