Laravel delete queued jobs using redis horizon artisan command

The question is how to delete all jobs which are queued in Laravel when you are using redis as the Queue driver.

To do this there are some options:

Option-1: general

Using the laravel-queue-clear package which is developed by Craig Morris that provides a useful tool to delete all kinds of queued jobs by an artisan command. This package is comprehensive and is not only for redis.

For wiping your queues clear you need to run this:

php artisan queue:clear [connection] [queue]

where [connection] is :

the name of a connection in your config/queue.php

and [queue] is:

the name of the queue / pipe you want to clear

Option-2: redis

In the terminal you can use this command :

FLUSHDB

Which comes from here this link.

$ redis-cli
127.0.0.1:6379> FLUSHDB
OK
127.0.0.1:6379> exit

Then the result in Laravel.dev/horizon is as follow and all the queued jobs will be cleared out easily:

Option-3: redis

use redis in a controller like:

use Redis;

And then in an action put this:

Redis::command('flushdb');

And then trigger that action through a route::get();

Option-5: redis

Make an artisan command by:

php artisan make:command FlushRedis --command=flush:redis

Then register it in the Kernel.php file in app/Console as follows:

Then in the handle() method of the FlushRedis.php file put this:

Redis::command('flushdb');

At the end, run the command:

php artisan flush:redis

It’s done! All the queued jobs will be wiped out.

Option-5: redis + tinker

Thanks to @edilsoncichon for hist nice comment and introducing this option.

In the terminal you can use this command :

php artisan tinker;

Then do this:

>>> use Redis;
>>> Redis :: command (‘flushdb’);

So no code writing is needed! ;)

Note:

Remind that Laravel out of the box has an artisan command to delete all of your failed jobs :

php artisan queue:flush

Thank you for reading! If you enjoyed this article:

Clap it ! Share it! Follow Me in Medium!

Also I’d like to hear your opinion on this article. If you have any doubt, question or suggestion please leave a comment below.

Have a very wonderful day!

Previous Stories You will Love:

Posting about Python and Laravel

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Android fundamentals 05.3: Adaptive layouts

🚀BSC Launcher Presale is SOLD OUT.

What is the difference between a hard link and a symbolic link?

How To Register A Domain Name?

AutoScaling Ec2 Instances based on CPU usage using Terraform

ETC Core 2020 Roadmap Announcement 🎉

A Student’s Guide to Creating and Publishing a Website

Setting a Dynamic Date filter in QuickSight (AWS)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Panjeh

Panjeh

Posting about Python and Laravel

More from Medium

Creating your own Oauth2 server using Laravel Passport —Implicit grant flow

Laravel Model boot() method

Laravel multithreading simulation package