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
How to get all pending jobs in laravel queue on redis?
提问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) );
$connection
is the Redis connection name which is null by default, and The $queue
is the name of the queue / tube which is 'default' by default!
$connection
是 Redis 连接名称,默认为空,而$queue
是队列/管的名称,默认为“默认”!
回答by Mouagip
回答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 redis
driver 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 tinker
and 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 Horizon 提供了一个仪表板来监控你的队列,并允许你对你的队列做更多的配置。
composer require laravel/horizon
php artisan vendor:publish --provider="Laravel\Horizon\HorizonServiceProvider"
You have to set .env
config file and config/horizon.php
file.
您必须设置.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');