Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Redis for Queues for Multiple Laravel Applications on a Single Server

I have a production laravel application and the staging application running on the same server. I am running redis, which I am using as my queue driver. They are obviously connected to different databases. The question is if jobs that are pushed onto the reds queue from the staging application will interfere with the production db and vice versa.

like image 860
Ben Avatar asked Jul 07 '15 15:07

Ben


People also ask

Is Redis good for queues?

One reason that Redis is optimal for queuing tasks is that it offers atomic operations, meaning that any mutations to data are performed immediately or in a single step. You will not run into the risk of different machines working on the same piece of data, or receiving different versions of the same data.

Is there any relation between Redis and laravel queues?

Laravel has a unified queueing API that lets you choose from various technologies such as Redis, Amazon SQS, Beanstalkd, or even an old-fashioned relational database system.

Is Redis a cache or queue?

From there, he developed Redis, which is now used as a database, cache, message broker, and queue. Redis delivers sub-millisecond response times, enabling millions of requests per second for real-time applications in industries like gaming, ad-tech, financial services, healthcare, and IoT.

How does Redis work with laravel?

Laravel supports the use of Redis, which uses caches for temporary data storage to speed up the process of performing database queries and getting feedback, which will, in turn, reduce the amount of time spent pulling up data.


1 Answers

I had this same problem, and it took me hours to find the solution.

https://laravel.com/docs/5.6/queues#driver-prerequisites says:

In order to use the redis queue driver, you should configure a Redis database connection in your config/database.php configuration file.

And then https://laravel.com/docs/5.6/redis#predis says:

In addition to the default host, port, database, and password server configuration options, Predis supports additional connection parameters that may be defined for each of your Redis servers. To utilize these additional configuration options, add them to your Redis server configuration in the config/database.php configuration file.

Reading the "connection parameters" page, I eventually found https://github.com/nrk/predis/wiki/Client-Options, which says that 'prefix' is a supported option.

So, you can edit your config/database.php configuration file to have:

'redis' => [
        'client' => 'predis',
        'cluster' => false,
        'options'=>[
            'prefix' => env('REDIS_PREFIX', 'YOUR_PREFIX_HERE')
        ],
        'default' => [
            'host'     => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port'     => env('REDIS_PORT', 6379),
            'database' => 0,
        ],
    ],

I'm not sure if you then need to restart Redis or Supervisord.

like image 64
Ryan Avatar answered Sep 20 '22 23:09

Ryan