dongsisui7562 2015-12-16 11:20
浏览 207

如何在Laravel 5中使用redis为多租户多数据库架构应用程序执行排队和缓存?

I am working on a multi-tenant multi-database architecture application using Laravel which basically means that every tenant in the application has their own database, own sets of users, resources and so on.

Now I am trying to implement queues and caching in the application, then I am trying to use redis for that. A sample code looks like this:

$mailer->send('emails.welcome', ['user' => $user], function ($message) use ($user) {
    $message->from("admin@admin.com", "Admin");
    $message->to($user->email, $user->first_name)->subject("Welcome!");
});

This is to send a welcome email to user sign-up. But the queuing is storing all the queues in the same database in the same Redis instance, different tenant emails will get mixed up as far as I can tell.

How do I hook into Laravel 5 and change the queue behavior to either store the jobs for each tenant in a separate database or store extra meta-information about the tenant a particular job belongs to? And then also how would I tell Laravel to parse that extra meta-information and connect to the right tenant database before proceeding with the job?

  • 写回答

2条回答

  • dongyang4615 2018-03-29 08:13
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数