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

时间:2019-02-11 07:09:36

标签: php memcached

如果我将user_用作键的前缀,则无法以某种方式存储一系列复杂的项目

php代码

$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);

此后,我调用getAllKeys()并检查其是否已存储...

我考虑过密钥长度,但这不是问题。检查密钥后,密钥长度为30个字符-但我已经有密钥为39个字符长度。

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

这是我的连接器,MemCached Server的运行总限制为4GB,项目限制为256mb。对象的类实现可序列化。 memcached在具有二进制支持的情况下进行编译

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

序列化数组$this->skills长约4500个字符(var_dump()

这有效-仅当我用user _

启动密钥时失败
$_MEMCACHED->set('cache_user_'.$this->getUserId().'_skills', $this->skills);

我也扩展了memcached以跟踪是否在某处删除了它

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
}
}

但我不

对于两个设置操作,设置后都会返回成功代码

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

0 个答案:

没有答案