Skip to content

Commit 62ed820

Browse files
committed
Adding Doctrine Redis cache
1 parent dc337ee commit 62ed820

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Cache\AdapterBundle\Factory;
4+
5+
use Cache\Adapter\Doctrine\DoctrineCachePool;
6+
use Cache\Adapter\Redis\RedisCachePool;
7+
use Doctrine\Common\Cache\RedisCache;
8+
use Predis\Client;
9+
10+
class DoctrineRedisFactory implements AdapterFactoryInterface
11+
{
12+
public function createAdapter(array $options = array())
13+
{
14+
if (!class_exists('Cache\Adapter\Doctrine\DoctrineCachePool')) {
15+
throw new \LogicException('You must install the "cache/doctrine-adapter" package to use the "doctrine_redis" provider.');
16+
}
17+
18+
// TODO validate the options with symfony options resolver
19+
// TODO get ip, port and protocol from options.
20+
21+
$redis = new \Redis();
22+
$redis->connect('127.0.0.1', '6379');
23+
24+
$client = new RedisCache();
25+
$client->setRedis($redis);
26+
27+
return new DoctrineCachePool($client);
28+
}
29+
}

src/Resources/config/services.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ parameters:
1414
services:
1515
cache.factory.redis:
1616
class: Cache\AdapterBundle\Factory\RedisFactory
17+
18+
cache.factory.doctrine_redis:
19+
class: Cache\AdapterBundle\Factory\DoctrineRedisFactory
20+

0 commit comments

Comments
 (0)