laravel队列使用速率限制


每 60 秒限制 2 条通过

public function __construct(Model $dispatch, int $registerStatus, string $action)
    {
        $this->dispatch = $dispatch;
        $this->registerStatus = $registerStatus;
        $this->redisBlock = env('REDIS_BLOCK', 59);
        $this->redisAllow = env('REDIS_ALLOW', 2);
        $this->redisEvery = env('REDIS_EVERY', 60);
        $this->action = $action;
    }

    /**
     * @throws \Illuminate\Contracts\Redis\LimiterTimeoutException
     */
    public function handle(): void
    {
        Redis::throttle('key')->block($this->redisBlock)
            ->allow($this->redisAllow)
            ->every($this->redisEvery)
            ->then(function () {
                $programSiteService = new ProgramSiteService();
                $programSiteService->injectC2($this->dispatch, $this->registerStatus, $this->action);

            }, function () {
                Log::error('获取不了锁');
                return $this->release(3);
            });


    }
https://learnku.com/laravel/t/61700

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注