How to get all pending jobs in Laravel queue on Redis?
When a Laravel application processes background tasks using the Redis driver, it relies on specific keys within the Redis database to manage job lifecycles. The standard flow involves pushing a job onto the jobs list (which acts as the queue), and when the worker picks it up, that entry is popped. However, if your workers are down, misconfigured, or if the queue:listen artisan command was never executed on a server where jobs were pushed, you end up with a backlog of pending work sitting in Redis.
Laravel does not provide a built-in Artisan command to list these specific pending jobs directly from the application layer. Unlike some database drivers where you might inspect a table, Redis stores queue data in a structured but non-relational format that requires manual inspection or third-party tools to navigate effectively. This gap often leaves developers guessing about what failed or simply unable to audit the state of the queue without external help.
To retrieve these jobs, you must interact directly with the Redis instance. The specific key holding your pending jobs is typically named jobs for the default queue connection. You can inspect this using the standard Redis CLI tool. Run the following command in your terminal:
redis-cli LRANGE jobs 0 -1
The LRANGE command retrieves all elements within a specified range. By using -1, you tell Redis to return every element from index 0 to the end of the list. The output will be a series of serialized job payloads. Each string represents a complete job object, including its class name and data. If your queue connection is configured with a specific prefix (set in config/queue.php), you must include that prefix in the command, for example:
redis-cli LRANGE myapp_jobs 0 -1
Once you have the raw strings, they are not human-readable yet because Laravel serializes them. To inspect the actual class names and arguments, you need to deserialize these strings. You can do this programmatically within a PHP script or directly in Redis using the EVAL command to run Lua scripts, though a simple PHP snippet is often cleaner for debugging:
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379); // Update with your Redis host/port
$key = 'jobs'; // Or 'myapp_jobs' if you use a prefix
while ($jobData = $redis->rPop($key)) {
// This mimics what Laravel's QueueJobPayload does internally
$payload = json_decode($jobData, true);
if (isset($payload['data'])) {
echo "Class: " . $payload['class'] . "\n";
echo "Raw Data: " . base64_encode($payload['data']) . "\n\n";
}
}
Note that rPop removes the job from the list. If you need to inspect without removing, use lRange as shown earlier and iterate through the results manually in your code. A safer approach for production environments is to push these items back onto a temporary "failed" or "audit" queue after inspection so you don't lose data while debugging.
Another option is to use Redis GUI tools like RedisInsight or RQ. These interfaces provide a visual representation of the jobs list, allowing you to see the payload structure without writing custom scripts. They are particularly useful for large queues where parsing raw output becomes unreadable.
If your application uses the default connection name defined in config/queue.php, ensure you are querying the correct key. The default prefix is usually empty, resulting in a key named jobs. If you have customized this prefix, failing to account for it will result in an empty list or errors when trying to parse non-existent keys.
Inspecting pending jobs is rarely the end of the story; identifying them is only half the battle. Once you understand what is stuck, you need a strategy to clear it. Simply deleting the key is destructive and bypasses Laravel's job tracking, which can lead to inconsistent state if you rely on failed_jobs for reporting. The robust approach is to re-queue these items to a separate monitoring queue or attempt to process them with a new worker instance that has been restarted and properly configured.
For teams managing complex queue architectures where manual Redis inspection becomes a bottleneck, consider integrating tools like LaravelCompany's observability solutions to monitor queue depth and health metrics automatically, reducing the need for manual CLI intervention in the future.