2016-10-17 5 views
4

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를 통해 액세스 레디 스하려고 할 때 지금은 정상적으로 작동

을 넣었습니다. 하지만 캐시 구성 요소를 사용할 때 :

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에 관한 정보가 없습니다.

실수로 어디에서 잘못했는지 알려주시겠습니까?

+0

누락'$ this-> cacheAdapter-> ($ cachedResources) 저장, 나는 믿을 수 없어' – malcolm

+0

그렇게 사소한했다 . 고맙습니다. @malcolm 대답으로 의견을 게시 할 수 있습니까? 동의하겠습니다. 그것은 작동합니다. – Robert

+0

감사합니다 :) 다행스럽게도 도움이 될 수 있습니다. :) – malcolm

답변

6

당신이 놓친 가장 중요한 것은 캐시에 결과를 저장하는 것입니다 :

$cachedResources->set($resources); 

$this->cacheAdapter->save($cachedResources);