Symfony 3.1缓存-删除项目在产品中不工作
我一直在使用Symfony 3.1和新的缓存组件(),我正在使用redis适配器 config.ymlSymfony 3.1缓存-删除项目在产品中不工作,symfony,caching,redis,symfony-3.1,Symfony,Caching,Redis,Symfony 3.1,我一直在使用Symfony 3.1和新的缓存组件(),我正在使用redis适配器 config.yml cache: app: cache.adapter.redis default_redis_provider: "redis://127.0.0.1:6379" 基本上,当我访问特定资源时,我将数据保存在redis中,当我发布文章时,我将数据从redis中删除 symfony处于开发模式时,数据将按预期从缓存中存储/删除。 但当我将其更改为prod时,“deleteItem”
cache:
app: cache.adapter.redis
default_redis_provider: "redis://127.0.0.1:6379"
基本上,当我访问特定资源时,我将数据保存在redis中,当我发布文章时,我将数据从redis中删除
symfony处于开发模式时,数据将按预期从缓存中存储/删除。
但当我将其更改为prod时,“deleteItem”不再从redis缓存中删除该项。。
我在日志中找不到任何错误,所以我对它有点迷茫
这是我如何使用缓存的示例
protected function getCache(){
return $this->get('cache.app');
}
public function getAction(){
$cacheItem = $this->getCache()->getItem('example-key');
$data = ... // Check cacheItem isHit() ...
$cacheItem->expiresAfter($this->defaultCacheTime);
$cacheItem->set($data);
$this->getCache()->save($cacheItem);
}
public function postAction() {
...
$this->getCache()->deleteItem('example-key');
}
更新-我已找到可能导致此问题的原因
这是symfony AbstractAdapter和RedisAdapter代码的一部分:
public function deleteItem($key)
{
return $this->deleteItems(array($key));
}
public function deleteItems(array $keys)
{
$ids = array();
foreach ($keys as $key) {
$ids[$key] = $this->getId($key);
unset($this->deferred[$key]);
}
try {
if ($this->doDelete($ids)) {
return true;
}
} catch (\Exception $e) {
}
$ok = true;
// When bulk-delete failed, retry each item individually
foreach ($ids as $key => $id) {
try {
$e = null;
if ($this->doDelete(array($id))) {
continue;
}
} catch (\Exception $e) {
}
CacheItem::log($this->logger, 'Failed to delete key "{key}"', array('key' => $key, 'exception' => $e));
$ok = false;
}
return $ok;
}
protected function doDelete(array $ids)
{
if ($ids) {
$this->redis->del($ids);
}
return true;
}
这是Predis StreamConnection.php代码的一部分:
public function writeRequest(CommandInterface $command)
{
$commandID = $command->getId();
$arguments = $command->getArguments();
$cmdlen = strlen($commandID);
$reqlen = count($arguments) + 1;
$buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandID}\r\n";
for ($i = 0, $reqlen--; $i < $reqlen; $i++) {
$argument = $arguments[$i];
$arglen = strlen($argument);
$buffer .= "\${$arglen}\r\n{$argument}\r\n";
}
$this->write($buffer);
}
我不知道这一切是否有意义,我想我会在symfony bug tracker中打开一个问题,我的错,这是由一个过时的Predis版本引起的,我想我有最新版本的Predis,但我没有 最新版本一切正常
protected function doDelete(array $ids)
{
if ($ids) {
$this->redis->del(array_values($ids));
}
return true;
}