Saturday, May 30, 2015

Laravel 5 and queues using redis - get amount scheduled jobs in queue

I'm currently digging into Laravel 5 and am using the queue component to put time consuming tasks in a queue, so they can be processed in the background. For performance reasons, I switched from using the database queue driver to use the redis queue driver. My application has a dashboard, which shows the amount of scheduled jobs for each queue in the queue system. Using the database queue driver, I used the following code:

Using the redis queue driver, Laravel creates a list for each queue on the redis server, so you can easily use the functions from the predis package, to interact with the redis server. To get the amount of jobs in a queue with the redis queue driver, I use the code as shown below.

I also needed the possibility to remove all jobs in a specific queue at once in my application. To do so, I used the code shown below.