laravel 如何在redis的laravel队列中获取所有待处理的作业?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35412779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:16:49  来源:igfitidea点击:

How to get all pending jobs in laravel queue on redis?

laravelredis

提问by rap-2-h

Queue listener was not started on a server, some jobs where pushed (using Redis driver).

队列侦听器未在服务器上启动,推送了一些作业(使用 Redis 驱动程序)。

How could I count (or get all) theses jobs ? I did not found any artisan command to get this information.

我怎么能算(或得到所有)这些工作?我没有找到任何工匠命令来获取此信息。

采纳答案by Torgheh

If someone still looking for an answer here is the way I do it:

如果有人仍然在这里寻找答案,我就是这样做的:

$connection = null;
$default = 'default';

//For the delayed jobs
var_dump( \Queue::getRedis()->connection($connection)->zrange('queues:'.$default.':delayed' ,0, -1) );

//For the reserved jobs
var_dump( \Queue::getRedis()->connection($connection)->zrange('queues:'.$default.':reserved' ,0, -1) );

$connectionis the Redis connection name which is null by default, and The $queueis the name of the queue / tube which is 'default' by default!

$connection是 Redis 连接名称,默认为空,而$queue是队列/管的名称,默认为“默认”!

回答by Mouagip

Since Laravel 5.3 you can simply use Queue::size()(see PR).

从 Laravel 5.3 开始,您可以简单地使用Queue::size()(参见PR)。

回答by Hyder B.

You can also use the Redis Facade directly by doing this:

您还可以通过执行以下操作直接使用 Redis Facade:

use Redis;

\Redis::lrange('queues:$queueName', 0, -1);

Tested in Laravel 5.6 but should work for all 5.X.

在 Laravel 5.6 中测试,但应该适用于所有 5.X。

回答by B? Loong A Nh?i

I am an PHP Laravel dev, 3 years, I have just known these command recently, so shame on me. ;(

我是一名 PHP Laravel 开发人员,3 年了,我最近才知道这些命令,真丢人。;(

If you are using redisdriver for your queue, you can countall remaining jobs by name:

如果您redis为队列使用驱动程序,则可以按名称计算所有剩余作业:

use Redis;

// List all keys with status (awaiting, reserved, delayed)
Redis::keys('*');

// Count by name
$queueName = 'default';
echo Redis::llen('queues:' . $queueName);

// To count by status:
echo Redis::zcount('queues:' . $queueName . ':delayed', '-inf', '+inf');
echo Redis::zcount('queues:' . $queueName . ':reserved', '-inf', '+inf');

To see the result immediately, you can use php artisan tinkerand hit Redis::llen('queues:default');.

要立即查看结果,您可以使用php artisan tinker并点击Redis::llen('queues:default');

回答by Alessandro

You can install Horizon. Laravel Horizon provides a dashboard for monitoring your queues, and allows you to do more configuration to your queue.

您可以安装地平线。Laravel Horizo​​n 提供了一个仪表板来监控你的队列,并允许你对你的队列做更多的配置。

composer require laravel/horizon

php artisan vendor:publish --provider="Laravel\Horizon\HorizonServiceProvider"

You have to set .envconfig file and config/horizon.phpfile.

您必须设置.env配置文件和config/horizon.php文件。

Tested with Laravel 5.6

使用 Laravel 5.6 测试

回答by Tudor Corcimar

If anybody is still looking approach for the older versions of the Laravel:

如果有人仍在寻找旧版本 Laravel 的方法:

$connection = 'queue';
$queueName = 'default';
$totalQueuedLeads = Redis::connection($connection)->zcount('queues:'.$queueName.':delayed' , '-inf', '+inf');