//发布消息
public function actionPub() {
$redis = $this->redis;
$data = array("code" => 200, "type" => 1, "msg" => "发送短信", "data" => array("phone" => 188888888888, "contents" => "短信内容"));
$redis->publish("chan-1", json_encode($data));
}
//订阅消息
public function actionSub() {
set_time_limit(0); //脚本执行时间
ini_set('default_socket_timeout', -1); //socket超时设置
$redis = $this->redis;
$redis->subscribe(["chan-1"], function ($redis, $chan, $msg) {
echo "can:" . $chan . "msg:" . $msg;
});
}
//订阅消息匹配模式
public function actionPsub() {
set_time_limit(0); //脚本执行时间
ini_set('default_socket_timeout', -1); //socket超时设置
$redis = $this->redis;
$redis->pSubscribe(["chan-*"], function ($redis, $pattern, $chan, $msg) {
echo "pattern:" . $pattern . "can:" . $chan . "msg:" . $msg;
});
}
//查询队列信息
public function actionPubsub() {
$redis = $this->redis;
$redis->pubsub("numpat"); //获取订阅数量 number
$arr = $redis->pubSub("channels"); //获取所有订阅主题
}