🤝 Introducing Redis Queues
Redis Queue is a Python package that allows you to queue jobs for background processing. Because many hosting providers will time out on lengthy HTTP queries, APIs should be designed to close requests as soon as possible. We may do this using Redis Queue by routing jobs to a queue and then to a worker for processing.
With Redis queues, the processing time of queues is faster than the database queues, and to run a high number of jobs on a project, it becomes difficult to run with database queues. Also, you don't get Horizon without Redis.
🤔 Why Laravel Horizon?
The Laravel horizon package is used to manage Laravel-powered Redis queues. It provides a beautiful dashboard for the queues. This package allows users to configure jobs, generate analytics, and monitor queue-related tasks, including job run-time, failure, throughput, etc. The configuration information of all the team members of the project is stored in a single file that can be controlled centrally.
This article shows you how to install and run Laravel horizon in your Laravel application. And in the end, I shall also share why I enjoy working with Laravel. Let’s get started.
✅ Step 1: Installing Redis on MAC and starting the Redis server
First, let me install Redis on my system. If it is already installed in yours, start the server and jump to Step 2.
To install Redis, you need to run the following command.
After installing the redis, start the server by using the below command.
If successful, you'll see the startup logs for Redis, and Redis will be running in the foreground.
✅ Step 2: Installing predis and configurations required for Redis in our application
Coming back to our application, let’s add some packages. So, to use Redis with PHP, a PHP Redis client is needed. Therefore, I have installed predis in our application by using the following command.
.env and set values as shown below.
Make changes in
config/database.php and replace
✅ Step 3: Installing Horizon package and its configuration
To install the package, run this command in the terminal
After installing Horizon, publish its assets using the
horizon:install Artisan command:
After publishing Horizon's assets, its primary configuration file will be
config/horizon.php. This configuration file allows us to configure the queue worker options for our application.
✅ Step 4: Starting the horizon
After the successful installation and configuration of the horizon. Now, let’s start our horizon by running the below command in the terminal.
After following all the steps given above, you will successfully be able to integrate Laravel Horizon into your application.
As a developer, I found Horizon helpful because of the following -
- It provides an easier way to manage Redis queues in Laravel.
- A very readable and understandable dashboard by which we can monitor your queue system.
- It offers various plugins to send alerts over multiple tools, such as Slack.
- It delivers an easy-to-use code-driven configuration.
- It also provides a very efficient auto-scaling of jobs feature.
This article helps you understand Laravel Horizon and interests you in implementing the same in your apps.