title: Integrating Symfony2 and Redis
body: <p>I am trying to integrate Redis with my Symfony API, I found this bundle : <a href="https://github.com/snc/SncRedisBundle/blob/master/Resources/doc/index.md" rel="nofollow">RedisBundle</a></p>
  
  <p>I installed it and configured so that I can cache Doctrine like so config.yml:</p>
  
  <pre><code># Doctrine Configuration
  doctrine:
      dbal:
          driver:   pdo_mysql
          host:     "%database_host%"
          port:     "%database_port%"
          dbname:   "%database_name%"
          user:     "%database_user%"
          password: "%database_password%"
          charset:  UTF8
  
      orm:
          auto_generate_proxy_classes: "%kernel.debug%"
          naming_strategy: doctrine.orm.naming_strategy.underscore
          auto_mapping: true
  
          metadata_cache_driver: redis
          # enable query caching
          query_cache_driver: redis
  
  snc_redis:
  # configure predis as client
  clients:
      default:
          type: predis
          alias: default
          dsn: redis://localhost
      doctrine:
          type: predis
          alias: doctrine
          dsn: redis://localhost
  # configure doctrine caching
  doctrine:
      metadata_cache:
          client: doctrine
          entity_manager: default
          document_manager: default
      result_cache:
          client: doctrine
          entity_manager: [default]
      query_cache:
          client: doctrine
          entity_manager: default
  </code></pre>
  
  <p>In my FetchBookRepository I am trying to use RedisCache there:</p>
  
  <pre><code>&lt;?php
  
  namespace BooksApi\BookBundle\Repositories;
  
  use Doctrine\ORM\EntityManager;
  use Doctrine\ORM\Query\QueryException;
  
  use Snc\RedisBundle\Doctrine\Cache\RedisCache;
  use Predis\Client;
  
  class FetchBookRepository
  {
      /**
       * @var EntityManager
       */
      public $em;
  
      /**
       * @param EntityManager $entityManager
       */
      public function __construct(
          EntityManager $entityManager
      ){
          $this-&gt;em = $entityManager;
      }
  
      /**
       * @param $id
       * @return null|object
       * @throws QueryException
       */
      public function fetchBook($id)
      {
  
          $predis = new RedisCache();
          $predis-&gt;setRedis(new Client);
          $cache_lifetime= 3600;
  
          try {
              $book = $this-&gt;em-&gt;getRepository('BooksApiBookBundle:BooksEntity')
                  -&gt;find($id);
  
          } catch (\Exception $ex) {
              $this-&gt;em-&gt;close();
              throw new QueryException('003', 502);
          }
  
          return $book;
      }
  }
  </code></pre>
  
  <p>I called the RedisCahce and Client classes but how do I now use it with my query..? I cant really find much on Google in regards to Symfony &amp; Redis.</p>
  
  <p>UPDATE:</p>
  
  <p>When I use redis-cli and type in MONITOR i get this output:</p>
  
  <pre><code>1454337749.112055 [0 127.0.0.1:60435] "GET" "[BooksApi\\BookBundle\\Entity\\BooksEntity$CLASSMETADATA][1]"
  </code></pre>