duannan3959 2019-02-11 07:09
浏览 109

memcached不存储具有特定键的复杂项目数组

Somehow I can't store an array of complex items if I put user_ as prefix for the key

The php code

$this->skills = [
    'defensiv' => DefensivSkill::getAllUserSkills($this),
    'offensiv' => OffensivSkill::getAllUserSkills($this),
    'spezial'  => SpezialSkill::getAllUserSkills($this),
    'pve'      => PVESkill::getAllUserSkills($this)
];

//is not stored
$_MEMCACHED->set('user_'.$this->getUserId().'_skills', $this->skills);

//is stored
$_MEMCACHED->set($this->getUserId().'_skills', $this->skills);

I call getAllKeys() after this and check if its stored...

I thought about the key length, but thats not the problem. After checking the key is 30 chars long - but I already have keys which are 39 chars long.

$_MEMCACHED = new Memcached();
$_MEMCACHED->addServer('localhost', 11212);
$_MEMCACHED->setOption(Memcached::OPT_PREFIX_KEY, 'hogsmeade_');
$_MEMCACHED->setOption(Memcached::OPT_SERIALIZER,  Memcached::SERIALIZER_IGBINARY);

This is my connector, the MemCached Server runs with 4GB total limit, and 256mb item limit. The classes of the object implements serializable. memcached is compiled with igbinary support

Memcached v1.5.12 php-memcached v3.0.3 lib_memcached 1.0.18

The serialized array $this->skills is ~4500chars long (var_dump())

This works - only fails if I start the key with user_

$_MEMCACHED->set('cache_user_'.$this->getUserId().'_skills', $this->skills);

I did also extend memcached to track if I delete it somewhere

class MyMemcached extends Memcached
{
public function delete($key, $time = 0)
{
    file_put_contents(ROOT.'/memcache.log', 'DELETE '.$key, FILE_APPEND);
    parent::delete($key, $time); // TODO: Change the autogenerated stub
}

public function deleteMulti(array $keys, $time = 0)
{
    file_put_contents(ROOT.'/memcache.log', 'DELETE '.json_encode($keys), FILE_APPEND);
    parent::deleteMulti($keys, $time); // TODO: Change the autogenerated stub
}
}

but I dont

For both set actions the SUCCESS code is returned after set

$_MEMCACHED->set('user_'.$this->getUserId().'_skills', $this->skills); 
$_MEMCACHED->get('user_'.$this->getUserId().'_skills');
// works if I call it in the same execution
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 高价求中通快递查询接口
    • ¥15 解决一个加好友限制问题 或者有好的方案
    • ¥15 关于#java#的问题,请各位专家解答!
    • ¥15 急matlab编程仿真二阶震荡系统
    • ¥20 TEC-9的数据通路实验
    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?