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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧