1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| <?php
/**
* redis实战
*
* 发布
*
* @author <https://github.com/wuxiumu>
*/
//发布
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$redis->publish('msg', '来自msg频道的推送');
echo "msg频道消息推送成功~ \n";
$redis->close();
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| <?php
/**
* redis实战
*
* 订阅
*
* @author <https://github.com/wuxiumu>
*/
// ini_set(‘default_socket_timeout’, -1);
$redis = new \Redis();
$redis->pconnect('127.0.0.1', 6379);
//订阅
echo "订阅msg这个频道,等待消息推送... \n";
$redis->subscribe(['msg'], 'callfun');
function callfun($redis, $channel, $msg)
{
print_r([
'redis' => $redis,
'channel' => $channel,
'msg' => $msg
]);
}
|