PHP code example of mix / redis-subscriber
1. Go to this page and download the library: Download mix/redis-subscriber library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mix / redis-subscriber example snippets
$sub = new \Mix\Redis\Subscriber\Subscriber('127.0.0.1', 6379, '', 5); // 连接失败将抛出异常
$sub->subscribe('foo', 'bar'); // 订阅失败将抛出异常
$chan = $sub->channel();
while (true) {
$data = $chan->pop();
if (empty($data)) { // 手动close与redis异常断开都会导致返回false
if (!$sub->closed) {
// redis异常断开处理
var_dump('Redis connection is disconnected abnormally');
}
break;
}
var_dump($data);
}