Spreading key/value pairs across multiple memcached servers

Brad Fitzpatrick brad at danga.com
Wed Dec 1 08:56:47 PST 2004

On Wed, 1 Dec 2004, Chris Hartjes wrote:

> Pardon my ignorance of memcached as I post the following scenario:
> 1) I create an instance of a memecached client (PHP version)
> 2) I'm using memcached to cache MySQL result sets, using the query
> itself as the key
> 3) I ask memcached "hey, retrieve this key from memcache for me"
> Now, if I have two servers, what server will it talk to in order to
> find out where the key is?

The right one.

The memcached client library knows how to find the right server
immediately, without searching them all.  It uses a hash function to
calculate the hash of the key, mod the number of memcached servers.


> Will it always talk to the first server in
> the list?  I understand that the various servers are aware of what
> server a particular key is on.  I also understand it will only take
> one request to find out where a key is.  But again, will that request
> for the location of the key always go to one server?

It will go to no server.  It doesn't need to ask anybody where the key
is at.  It just knows.

- Brad

More information about the memcached mailing list