php – 使用Redis设置Symfony 3.1缓存组件
作者:互联网
我尝试使用Redis设置Symfony 3.1缓存.我按照本教程:
https://symfony.com/blog/new-in-symfony-3-1-cache-component
我安装了predis / predis和SncRedisBundle.
在我的config.yml我已经把
framework:
cache:
app: cache.adapter.redis
default_redis_provider: redis://192.168.34.10
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://192.168.34.10
logging: %kernel.debug%
cache:
type: predis
alias: cache
dsn: redis://192.168.34.10
logging: %kernel.debug%
options:
connection_timeout: 10
read_write_timeout: 30
现在,当我尝试通过snc_redis访问redis时,它正常工作.但是当我尝试使用缓存组件时:
public function getLoggedUserAcl($userId)
{
$cachedResources = $this->cacheAdapter->getItem('acl.rules');
$cachedResources->expiresAfter(100);
if ($cachedResources->isHit()) {
dump('hit');
$resources = $cachedResources->get();
} else {
dump('not-hit');
$resources = $this->api->getCollection(Resource::class, null, null, [
'userId' => $userId
]);
$cachedResources->set($resources);
}
return $resources;
}
CacheAdapter是@ cache.app服务.
它一直转储NOT_HIT.在日志中,REDIS没有任何内容.
你能告诉我哪里弄错了或者暗示我可能出错了吗?
解决方法:
您在这里错过的最重要的事情是将结果保存到缓存:
$cachedResources->set($resources);
$this->cacheAdapter->save($cachedResources);
标签:php,redis,symfony,symfony-3-1,symfony-cache 来源: https://codeday.me/bug/20190527/1165545.html