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
  • 相关阅读:
    告别单身淘宝小店
    微信机器人 细腻化
    # 导入模块 from wxpy import * # 初始化机器人,扫码登陆 bot = Bot()
    减小文件大小 减少 帧
    无有效图视频
    生成一张白色图片的算法--逻辑
    加logo
    字幕 3系数
    音频分析 字幕同步
    尊重百度的api语音合成规则
  • 原文地址:https://www.cnblogs.com/yifan72/p/9661406.html
Copyright © 2011-2022 走看看