Question

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!

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top