Answer the question
In order to leave comments, you need to log in
Problem communicating php and python via memcached?
if a set is made from php to memcache, then when I try to do a get by such a key from python, I get:
>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))<br/>
/usr/bin/python2.6 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) <br/>
[GCC 4.4.5]<br/>
>>> import memcache<br/>
>>> import binascii<br/>
>>> m=memcache.Client(['127.0.0.1:11211'], debug=0)<br/>
>>> def php_hash(key):<br/>
... return (binascii.crc32(key) >> 16) & 0x7fff<br/>
... <br/>
>>> m.get((php_hash(mfd.php_nexttime), mfd.php_nexttime))<br/>
Traceback (most recent call last):<br/>
File "", line 1, in NameError: name 'mfd' is not defined<br/>
>>> m.get((php_hash('mfd.php_nexttime'), 'mfd.php_nexttime'))<br/>
Traceback (most recent call last):<br/>
File "", line 1, in File "/usr/lib/pymodules/python2.6/memcache.py", line 779, in get<br/>
return self._get('get', key)<br/>
File "/usr/lib/pymodules/python2.6/memcache.py", line 766, in _get<br/>
value = self._recv_value(server, flags, rlen)<br/>
File "/usr/lib/pymodules/python2.6/memcache.py", line 915, in _recv_value<br/>
return val<br/>
UnboundLocalError: local variable 'val' referenced before assignment<br/>
<br/>
Устал гуглить может кто ни будь сталкивался?
Answer the question
In order to leave comments, you need to log in
Apparently you will have to get into the source code of the python client and fix everything related to flags there. In flags (768 and 300 for example), clients store information about how they encoded (serialized) the data. see github.com/memcached/memcached/blob/master/doc/protocol.txt#L155
In your case VALUE mfd.php_nexttime 768 10
the flag is 768 and 10 is the response length (10 bytes). I just didn’t quite understand why you have different flags for the same key (because there was the same value both times ??)
If you use the same serialization methods on both ends (php-python), look at what flags the PHP client marks them with and replace them in the Python client with similar ones or use the default text flag. More specifically, I’m unlikely to tell you. there you just need to poke around in the code and edit it. (see the _recv_value(self, server, flags, rlen) function in the client sources, you can write val = buf as an option for
else: val = buf# like this!! self.debuglog("unknown flags on get: %x\n" % flags))
python probably tries to deserialize the value right away and breaks off - the syntax of the php serializer is not familiar to him ... the decision to push the encoded value into the json memcache and decode it in python, well, or any other "standard format"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question