1. laravel消息订阅

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Redis;

class TestMtQuote extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'quote:real';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'mt_server test';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $that = $this;
        try{
            $redis = Redis::connection('mt_server'); # mt_server redis 配置链接
            Redis::psubscribe(['PUBQUOTE:REAL'], function($message) use($that){
                $data = json_decode($message,1);
                $that->test($data);
            },'mt_server');
        }catch (\Exception $e){
            dump($e->getLine(),$e->getFile(),$e->getMessage());
        }

    }
    public function test($arr=[]){
        dump($arr);
    }
}

results matching ""

    No results matching ""