Take the 2-minute tour ×

So I am making a small multiplayer game and I am using php as the backend. I basically need to SET and GET a lot of positions of objects, well one object is one player that has a X/Y position in this case.

I don't need todo it in realtime, but perhaps every 5-20 seconds since it's turn based. I don't mind if I loose data since positions will be set again by the clients every now and then.

I was thinking of doing this with memcached, or redis. Basically each player would be a "key" and this key would contain an object with some relevant information, but the most important thing beeing the X/Y positions.

Perhaps I am going about this the wrong way but, this approach would seem very easy to do, however I am not sure how well it would work since I don't have a lot of experience with either of these soutions.

I should add that we are talking about perhaps 10 players here, hence 10 objects with x/y positions that needs updating every now and then.

Can it be done like this, is there a better solution than memcached/redis? If not which of these two would be better performance-wise? From what I understand it's almost the same thing, just that redis offers some more functionality (Which may not necessarily be needed).

Oh and yes I am also using APC with php obviously. Thanks!

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

With just 10 objects in the entire data model, I would store them all as a serialized array under a single key. The serialization time will pale in comparison to the memcached call, so you may as well minimize the number of reads and writes to one.

I just checked out the redis online demo, and it looks pretty neat. Thanks for the link. I can't speak to which is better, but memcached in PHP is proven and mature so you can't go wrong there.

share|improve this answer
Yeah I guess, I wonder though on a PHP driver level which consumes less resources, a new memcache(); or a new redis() and who is cheapest on resources when connecting/setting/getting stuff –  neph Feb 16 '11 at 12:14
By creating an agnostic service layer on top of whichever one you pick that provides the model-specific methods you need, you can always swap out one for the other later without changing the application that uses it. Don't litter your code with memcache::get() calls! Instead, place those inside a GameServiceMemcache implementation of a backend-neutral GameService interface. –  David Harkness Feb 17 '11 at 2:20
add comment

Redis is cheapest on resources, especially 32 bit version, e.g. if you use less 2 GB cache memory, which is the case I believe, run 23 bit Redis even if your server is 64 bit.

share|improve this answer
add comment

Your Answer


