On Dec 3, 2:50 pm, "Brian Rue" <
brian...@gmail.com> wrote:
> I'm not sure about libmemcached so I can't answer the original question, but
> to get the pecl php client and the python-memcached to work together (that's
> what it looks like you're using), change your python code to this:
> <code>
> import memcache
> import binascii
> m = memcache.Client(['
192.168.28.7:11211', '
192.168.28.8:11211
> ', '192.168.28.9:11211'])
>
> def php_hash(key):
> return (binascii.crc32(key) >> 16) & 0x7fff
>
> for i in range(30):
> key = 'key' + str(i)
> a = m.get((php_hash(key), key))
> print i, a
> </code>
>
> (this assumes that php is set up with the defaults--standard hashing, crc32)
>
> For whatever reason, the pecl php client doesn't use a straight crc32 and
> instead does what's in the php_hash function above. Calculating the hash
> value yourself in python and passing a tuple of (hash_value, key) to get()
> (or set, delete, etc) does the trick. You could also subclass
> memcache.Client, I suppose.
>
> Hope this helps,
>
> Brian Rue
>