Skip to content

Commit 7e70e77

Browse files
committed
Added PHPRedis factory
1 parent 9ac1fee commit 7e70e77

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

src/Factory/DoctrineRedisFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class DoctrineRedisFactory extends AbstractAdapterFactory
2929
*/
3030
public function getAdapter(array $config)
3131
{
32-
if (!class_exists('Cache\Adapter\Doctrine\DoctrineCachePool')) {
33-
throw new \LogicException('You must install the "cache/doctrine-adapter" package to use the "doctrine_redis" provider.');
34-
}
35-
3632
$redis = new \Redis();
3733
$redis->connect($config['host'], $config['port']);
3834

src/Factory/PhpRedisFactory.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Adapter\PhpRedis\PhpRedisCachePool;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
17+
/**
18+
* @author Tobias Nyholm <[email protected]>
19+
*/
20+
class PhpRedisFactory extends AbstractAdapterFactory
21+
{
22+
protected static $dependencies = [
23+
['requiredClass' => 'Cache\Adapter\PhpRedis\PhpRedisCachePool', 'packageName' => 'cache/phpredis-adapter'],
24+
];
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getAdapter(array $config)
30+
{
31+
$client = new \Redis();
32+
$client->client($config['host'], $config['port']);
33+
34+
return new PhpRedisCachePool($client);
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
protected static function configureOptionResolver(OptionsResolver $resolver)
41+
{
42+
$resolver->setDefaults([
43+
'host' => '127.0.0.1',
44+
'port' => '6379',
45+
]);
46+
47+
$resolver->setAllowedTypes('host', ['string']);
48+
$resolver->setAllowedTypes('port', ['string', 'int']);
49+
}
50+
}

0 commit comments

Comments
 (0)