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
  • 相关阅读:
    链表与顺序表
    js对table的动态操作
    关于float的内部结构
    spring bean的生命周期
    浅谈(吐槽)自己
    java缓存机制(上)
    Verilog经典输入控制/激励信号模板1
    verilog中的for循环问题
    2015,welcome!!!
    (转)Quartus II和Modelsim的联合仿真(详细)
  • 原文地址:https://www.cnblogs.com/yifan72/p/9661406.html
Copyright © 2011-2022 走看看