redis键过期通知
作者QQ:67065435 QQ群:821635552
本站内容全部为作者原创,转载请注明出处!
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();