sub.php 434 B

123456789101112131415161718192021
  1. <?php
  2. go(function () {
  3. $redis = new Swoole\Coroutine\Redis();
  4. $ret = $redis->connect('192.168.1.220', 6379);
  5. $msg = $redis->subscribe(['refill']);
  6. while (true)
  7. {
  8. $msg = $redis->recv(60);
  9. var_dump($msg);
  10. $redis->close();
  11. if(empty($msg)) continue;
  12. if(count($msg) !== 3) continue;
  13. $channel = $msg[1];
  14. $content = unserialize($msg[2]);
  15. $type = $content['type'];
  16. $val = $content['value'];
  17. }
  18. });