PHP+Redis发布订阅
PHP+Redis发布订阅
提示: redis发布订阅通知基于socket,连接超时受配置影响,可以修改php.ini,或者动态添加 ini_set('default_socket_timeout', -1); pub.php ``` $redis = new Redis(); // 第一个参数为redis服务器的ip,第二个为端口 $res = $redis->connect('127.0.0.1', 6379); // test为发布的频道名称,hello,world为发布的消息 $res = $redis->publish('test','hello,world'); ``` sub.php ``` $redis = new Redis(); $res = $redis->connect('127.0.0.1', 6379,0); $redis->subscribe(array('test'), 'callback'); // 回调函数,这里写处理逻辑 function callback($instance, $channelName, $message) { echo $channelName, "==>", $message,PHP_EOL; } ```
相关推荐
王道革 2020-11-25
wangdonghello 2020-11-03
Langeldep 2020-11-16
chenhualong0 2020-11-16
聚合室 2020-11-16
koushr 2020-11-12
MRFENGG 2020-11-11
guoyanga 2020-11-10
fackyou00 2020-11-10
Orangesss 2020-11-03
dongCSDN 2020-10-31
rainandtear 2020-10-30
Quietboy 2020-10-30
liuyulong 2020-10-29
fansili 2020-10-29
温攀峰 2020-10-23
jackbon 2020-10-19
kaixinfelix 2020-10-04