php - mysql调用接口实现数据同步的问题
伊谢尔伦
伊谢尔伦 2017-05-16 13:06:33
0
2
719

1.情景描述:
现在本地数据库需要与药房数据库同步库存(字段)信息,实现方式是调用药房的接口获得单一药品的库存。
2.解决方案:
定时任务时间,如果几分钟(例如:2分钟)同步一次,我查询本地数据库遍历每条记录调接口,更新每条记录。
3.问题:
本地数据库几万条数据,同时取出操作内存肯定会爆掉,而且2分钟还没同步完,又重新执行怎么办?

有点模糊的思路,分块取,例如每次取100条进行更新。怎么设计,测试才能达到一个比较好的效果呢?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
洪涛

I don’t quite understand the requirements, so I can only give you a reference:

1. If you have permission to modify the pharmacy database:

直接在药房数据库添加一个触发器,当库存修改的时候,
主动同步到本地(前提是本地要做映射,也就是可以在外面访问)。

2. If you do not have the right to modify the pharmacy database:

其实是不需要,每隔2分钟去同步一次的。本地在展示的时候,比如,
一页展示10个产品,那在取数据时候,数据的库存字段是去药房取,
而其它字段在本地取(远程取来的时候,做一个本地缓存,防止多从访问去远程取多次)

我想大声告诉你

The author first confirms that by calling the inventory of a single drug through the interface, can you check it all in 2 minutes? If so, it is better to use Redis to save such frequent IO operations first, and then make a scheduled task and insert it into the database later.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!