还有一种sub pub消息
消息生产端
<?php消息订阅端,可一次订阅不同的通道消息
$channelName = "testPubSub";
$channelName2 = "testPubSub2";
//向指定频道发送消息
try {
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
for ($i = 0; $i < 5; $i++) {
$data = array('key' => 'key'.$i, 'data' => 'testdata');
$ret = $redis->publish($channelName, json_encode($data));
print_r($ret);
}
} catch (Exception $e) {
echo $e->getMessage();
}
<?php
//声明测试频道名称
$channelName = "testPubSub";
$channelName2 = "testPubSub2";
$redis = new Redis();
//建立一个长链接
$redis->connect('127.0.0.1', 6379);
try {
$redis->subscribe(array($channelName, $channelName2), function ($redis, $chan, $msg) {
echo "channel:".$chan.",message:".$msg."\n";
});
} catch (Exception $e) {
echo $e->getMessage()."\n";
}
网友回复
ai大模型是不是遇到瓶颈了,现在只优化速度了?
python能写一个检测nginx rewrite高危漏洞的工具代码?
css如何给video视频进行mask遮罩?
windows如何同时允许两个用户远程桌面连接同一个电脑?
nginx升级到1.30.1导致无法启动 [emerg] SSL_CTX_new() failed怎么办?
什么是ASLR(地址随机化)?
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?


