In this post I’ll talk about how to setup Laravel queues using redis, and how to make them perform faster.
By default laravel waits 3 seconds before pulling new jobs into the queue. In this post we’ll learn how to eliminate this delay and make it perform faster.
What ?! Redis ?
Redis is a key-value based, in-memory NoSQL database which has serveral use cases. In this post we’re going to use it as a message queue for Laravel.
This tutorial assumes that you have already installed:
If you have not installed them click on them to see the installation guide.
And assumes that you already know what is laravel queues and how it works if don’t make sure to read the article below:
NOTE: The redis installation guide contains important steps about making your redis to start on startup follow the instructions carefully.
Configuring Laravel to Use Redis
In order to configure laravel to use redis as your queue driver, first:
composer require predis/predis
And then change this line in the .env
Also make sure to correctly populate below paramateres:
REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379
Make it FAST :)
Instead of simply running the
php artisan queue:work which by
default waits 3 seconds before pulling new jobs you can use
php artisan queue:work --sleep=0 which doesn’t sleep before pulling
Depending on the configuration that you are using for your redis make sure to change this in it. To make sure that it works perfectly fine.comments powered by Disqus