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 MATLAB动图的问题
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名