zoukankan      html  css  js  c++  java
  • laravel发布订阅

    1、php artisan make:command RedisSubscribe

     在app console中会生成RedisSubscribe.php文件

      

    <?php

    namespace AppConsoleCommands;

    use IlluminateConsoleCommand;
    use IlluminateSupportFacadesRedis;

    class RedisSubscribe extends Command
    {
    /**
    * The name and signature of the console command.
    *
    * @var string
    */
    protected $signature = 'redis:subscribe';//自行修改

    /**
    * The console command description.
    *
    * @var string
    */
    protected $description = 'Subscribe to a Redis channel';//自行修改

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

    /**
    * Execute the console command.
    *
    * @return mixed
    */
    public function handle()
    {
    Redis::subscribe(['test-channel'], function ($message) {
    echo $message;
    });
    //
    }
    }

    2、用php Artisan生产命令
      1).在Kernel中添加配置:
        protected $commands = [
        CommandsRedisSubscribe::class,
      //
        ];

      2).php artisan make:command subscribe
    3、在控制器里面使用方法:
      
    Redis::publish('test-channel', "sdsdsadad")

    4、修改redis配置执行时间
    在config/database.php的redis配置中添加
    'read_write_timeout' => 0,//new


    参考:https://www.jianshu.com/p/7eef26de7c45
    callback参考:https://www.jianshu.com/p/41677357d736
  • 相关阅读:
    BZOJ1691: [Usaco2007 Dec]挑剔的美食家
    BZOJ1584: [Usaco2009 Mar]Cleaning Up 打扫卫生
    BZOJ3057: 圣主的考验
    BZOJ1770: [Usaco2009 Nov]lights 燈
    1710: [Usaco2007 Open]Cheappal 廉价回文
    「Poetize7」电话线路
    「Poetize6」Candle
    「Poetize5」水叮当的舞步
    解题:CF983A Finite or not
    解题:POI 2013 Triumphal arch
  • 原文地址:https://www.cnblogs.com/yifan72/p/9661406.html
Copyright © 2011-2022 走看看