ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
消息发布端 // test为发布的频道名称,hello,world为发布的消息 $res = $redis->publish('test','hello,world'); 消息订阅端 (1)$redis->subscribe(array('test'), 'callback'); // 回调函数,这里写处理逻辑 function callback($instance, $channelName, $message) { echo $channelName, "==>", $message,PHP_EOL; } (2)$redis->subscribe(array($channelName, $channelName2), function ($redis, $chan, $msg){ echo "channel:".$chan.",message:".$msg."\n"; }); (3)$redis->psubscribe(['phone:switch'], [$this, 'sendTask']); public function sendTask($ins, $pattern, $channel, $data){ $this->ws->task($data); }