doudi7782 2012-10-07 17:13
浏览 39
已采纳

高流量 - 多个请求设置相同的memcached密钥?

I'm setting up memcached. I have a couple questions regarding high traffic and best practice for updating/setting keys. I'm creating a online game where users are assigned points in a increment of 10,50,100.

Use : Store user "game stats" in keys and running a cron job every 5 minutes or so to update the stats permanently in the datastore. This way the "game" can function without ever going to the db to crud values, points.

Will use warm up scripts to pull and populate keys for user stats

Questions :
1)Would there be a issue down the road with high traffic and trying to write to that users points key?

2)Best practice for incrementing values in memcache?

This is a rough idea of what I'm using now

$newval = $memcache->get( $key ); 
$memcache->set($key, $newval+10, false, 1000) or die ("Failed to save data at the server");

3)Recommendations for storing users game stats in memcache? Any input would be greatly appreciated.

Thank you all!

  • 写回答

1条回答 默认 最新

  • dotxxh0998 2012-10-07 17:20
    关注

    Use Memcache's increment function to avoid potential race conditions when incrementing values stored in Memcache.

    If you need to do other math besides incrementing (e.g. resetting to zero), use compare and swap (cas).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊