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

On Wed, Dec 3, 2008 at 1:35 AM, ruturajv <[EMAIL PROTECTED]> wrote:

>
> I too faced similar problem, eg
>
> using.. PHP
>
> <code>
> <?php
> $m = new Memcache;
> $m->addserver('192.168.28.7, 11211);
> $m->addserver('192.168.28.8, 11211);
> $m->addserver('192.168.28.9, 11211);
> for ($i=0; $i<30; $i++) {
>    $v = $m->set('fkey'.$i, $i);
> //    $va = $m->get('key'.$i);
>    var_dump($va);
> }
> </code>
>
> and I'm unable to retrieve "ALL" keys using this (Python)
>
> <code>
> import memcache
> m = memcache.Client(['192.168.28.7:11211', '192.168.28.8:11211',
> '192.168.28.9:11211'])
>
> for i in range(30):
>        a = m.get('key'+str(i))
>        print i, a
>
> </code>
>
> On Dec 3, 1:43 pm, "matt farey" <[EMAIL PROTECTED]> wrote:
> > Sorry for top post, have you looked at using thrift (apache incubator)
> and memcached together, ala facebook?
> >
> > Sent from my BlackBerry(R) wireless device
> >
> > -----Original Message-----
> > From: aniketh <[EMAIL PROTECTED]>
> >
> > Date: Wed, 3 Dec 2008 00:12:02
> > To: memcached<[email protected]>
> > Subject: using memcached with c and python api
> >
> > hey,
> >
> > i've been trying to use the libmemcached api from c and the python
> > api
> > to access memcached.
> >
> > however, i have come across a problem. I am setting values on multiple
> > servers using c, and attempting to retrieve it using python
> >
> > fetching the keys back in c works fine, but python throws a lot of
> > "not found". i'm guessing it is something to do with the hash
> > algorithm. i tried setting it to crc32 in c, but it does not help.
> >
> > any pointers would be appreciated.
> >
> > thanks
> >
> > regards,
> > aniketh
>

Reply via email to