Question to Cache::Memcached

Brad Fitzpatrick
Mon, 7 Jun 2004 12:09:18 -0700 (PDT)

> How does the module decide which backend to give it too (if no weight value is
> specified)?

It runs the key through a hashing function, then mods that number with the
number of buckets (number of servers * each's weight) and uses the result
as the bucket number.

So if you have two servers: weight 1   ->  1 bucket  (bucket 0) weight 3   ->  3 buckets (bucket 1, 2, 3)

Total:                  4 buckets

So now we have key "foobar".  HashValue("foobar") = 238423432423434.

Taking the hash value, mod 4 (4 buckets)...

 238423432423434 % 4 = 2 (bucket 2)

So it uses

> Is there a restriction on how the keys may look?

No spaces or newlines.

> My keys are similar to this (without quotes):
> "010/dating/profilansicht/profilAnsicht.xmlindex=page1userid=2170797"

That looks fine.

So the mystery is:  what hash values is it calculating for your keys?
It'd be way too weird if they were all 0.