この記事では分散遅延タスクを実装するためのReidsキースペース通知とTP5を中心に紹介しますので、困っている友人の参考になれば幸いです!
テスト環境: Windows 10 phpStudy
redis 構成ファイル redis.windows.conf
notify-keyspace-events "Ex"
redis サービスを再起動
psubscribe __keyevent@0__:expired
C:\Users\admin>redis-cli 127.0.0.1:6379> psubscribe __keyevent@0__:expired Reading messages... (press Ctrl-C to quit) 1) "psubscribe" 2) "__keyevent@0__:expired" 3) (integer) 1
setName('pay') ->addArgument('type', Argument::REQUIRED, "the type of the task that pay needs to run") ->setDescription('this is payment system command line tools'); } // 执行指令 public function execute(Input $input, Output $output) { $type = $input->getArgument('type'); if ($type == 'psubscribe') { // 发布订阅任务 $this->psubscribe(); } } /** * Redis 发布订阅模式 */ private function psubscribe() { $service = new RedisSubscribe(); $service->sub(); } }
setOption(\Redis::OPT_READ_TIMEOUT, -1); $redis->psubscribe(array('__keyevent@0__:expired'), function ($redis, $pattern, $chan, $msg) { Log::error('[1]--过期事件的订阅 ' . $msg); }); } }
php think pay psubscribe
C:\Users\admin>redis-cli 127.0.0.1:6379> setex UserName 10 Tinywan OK 127.0.0.1:6379> get UserName "Tinywan" 127.0.0.1:6379> get UserName (nil) 127.0.0.1:6379>
PHP7 チュートリアル》
以上がPHP7 の Reid キー空間通知は TP5 と連携して分散遅延タスクを実装しますの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。