在CakePHP中使用不同的MySql DB进行写操作 [英] Using a different MySql DB for write operations in CakePHP

查看:287
本文介绍了在CakePHP中使用不同的MySql DB进行写操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要缩放我的mysql RDS实例。我可以在亚马逊RDS中启动只读副本,但问题是写操作将不能在只读副本上工作。我需要重定向主服务器上的所有写操作(INSERT,UPDATE,DELETE),以及对只读副本的所有读操作。

I need to scale my mysql RDS instance. I can launch read replicas in amazon RDS, but problem is that the write operations won't work on read replicas. I need to redirect all the write operations (INSERT, UPDATE, DELETE) on master server somehow, and all the read operations on a read replica.

RDS将负责将只读副本与最新更改同步。

RDS will take care of synchronizing the read replica with latest changes.

有任何简单的修改方法蛋糕在不同的DB上执行所有的写命令?而不更改控制器或模型?

is there any easy way to modify cake to execute all the write commands on a different DB? without changing the controllers or models?

我现有的服务器无法处理连接和cpu峰值。已经尝试升级它,但它没有工作。

my existing server is not able to handle the connections and cpu spikes. already tried to upgrade it, but it did not work.

感谢您的帮助。
谢谢。

I appreciate your help. Thank You.

推荐答案

在AppModel :: beforeSave()中设置不同的数据源并将其设置回另一个in afterSave()。

Set a different datasource in AppModel::beforeSave() and set it back to another one in afterSave().

这篇关于在CakePHP中使用不同的MySql DB进行写操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆