PHP Memcached重复记录

时间:2013-11-21 05:14:28

标签: php memcached duplicate-data

我们使用memcached + PHP并拥有单一服务器环境。我们使用脏和持久(commit)方法将数据更新到DB。问题是我们发现记录偶尔会在DB中重复两次。 更新脏的代码如下:

$cache->get('dirty');//the dirty hold all the sql statment that need to be updated.
$updatedDirty = ....//add new data to dirty
$cache->set($updatedDirty, 'dirty', 3600);//lets say cache it for one hour. 

每20秒,服务器将运行以下脚本以将数据从脏持久(提交)到DB:

$toBeUpdated = $cache->get('dirty'); 
$cache->delete('dirty',0);
commit($toBeUpdated);

将脏值按值复制到$ toBeUpdated。然后脏缓存已删除。 这不是在$ cache-> get('dirty')之前或在$ cache-> get('dirty')之前重复记录的情况 因为重复发生在两个不同的提交批处理中。任何人都遇到过会导致记录重复问题的任何其他情况?非常感谢你的帮助!

0 个答案:

没有答案