redis键过期通知

  1. Redis键过期通知

     <?php
     class PublishMsg
     {
         public function index()
         {
             $redis = new Redis();
             $redis->connect("192.168.1.163", "6379");
             $redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
             $redis->subscribe(["__keyevent@0__:expired"], [$this, "getMsg"]);
         }
    
         public function getMsg($redis, $channel, $msg)
         {
             $chapter_key = $msg;
             $chapter_info = explode(':', $chapter_key);
             if(count($chapter_info) != 2 || $chapter_info[0] != 'xxx' || !is_numeric($chapter_info[1])){
                 return false;
             }
             echo $msg;
             echo "\n";
             return true;
         }
     }
    
     $publish_msg = new PublishMsg();
     $publish_msg->index();
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-07-08 16:49:59

results matching ""

    No results matching ""