我运行python脚本,缓存一些数据
self.cache.set('test', 'my sample data', 300)
data = self.cache.get('test')
self.p(data)
这个程序将导致打印'我的样本数据'...一切都很好,但是当我尝试从php访问此密钥时
$data = $this->cache->get('test');
print_r($test);
我只得到空的结果 所以我查看服务器统计信息
$list = array();
$allSlabs = $this->cache->getExtendedStats('slabs');
$items = $this->cache->getExtendedStats('items');
foreach($allSlabs as $server => $slabs) {
foreach($slabs AS $slabId => $slabMeta) {
$cdump = $this->cache->getExtendedStats('cachedump',(int)$slabId);
foreach($cdump AS $server => $entries) {
if($entries) {
foreach($entries AS $eName => $eData) {
$list[$eName] = array(
'key' => $eName,
'server' => $server,
'slabId' => $slabId,
'detail' => $eData,
'age' => $items[$server]['items'][$slabId]['age'],
);
}
}
}
}
}
ksort($list);
print_r($list);
这个关键'测试'就在那里......但我无法访问它
如果我在php中缓存某些内容我每次都会得到结果,但不知怎的,这个python + php缓存无法正常工作
如果有人知道哪里可能有问题请求建议......我会尝试一切
答案 0 :(得分:2)
可能是PHP和Python之间的哈希不匹配吗?这里有一个解决方案:http://www.ruturaj.net/python-php-memcache-hash
将以下内容添加到Python脚本中以更改计算哈希的方式......
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