How to perform queuing and caching using redis for a multi-tenant multi-database architecture application in Laravel 5? How to perform queuing and caching using redis for a multi-tenant multi-database architecture application in Laravel 5? laravel laravel

How to perform queuing and caching using redis for a multi-tenant multi-database architecture application in Laravel 5?


For appropriate work of Queue system, you need to use your own implementation of \Illuminate\Queue\SerializesModels trait inside your Jobs. Wheech will save and init correct DB connection on Job::__sleep() and Job::__wakeup(). Take a look at TenantAwareJob trait of hyn/multi-tenant package.

For appropriate work of Cache system, you need to use a prefix which depends on the current host. Take a look how hyn/multi-tenant developers recommend to implement this.


This shouldn't be a problem generally as the queue is simply a queue. i.e. the tasks in it contain the real needed data, if you want to 'categorize' the queues for better management, you may the onQueue method to specify the queue or onConnection to specify the connection you want to dispatch to.

e.g.

EmailJob::dispatch($podcast)    ->onConnection('sqs')    ->onQueue('tenant1');

You may also create a queue for a particular connection as follows and push jobs to it:

$tenant1Connection = Queue::connection('connection_name');$tenant1Connection->pushOn('queue_name', $job)

If you need to avoid the facade, you can do:

app('queue')->connection('connection_name')->pushOn('queue_name', $job);