RedisCache driver implementation #109

merged 4 commits into from Mar 30, 2012

5 participants

o commented Feb 29, 2012

This class implements Redis key-value store ( as cache driver.

It uses redis php extension ( for communicating with Redis.

Running tests

To pass tests, you need to install redis to your box.

From source

tar xvzf redis-stable.tar.gz
cd redis-stable

From apt-get

apt-get install redis-server

From homebrew

brew install redis

Then run redis-server and phpunit.

o added some commits Feb 29, 2012
@o o Added redis cache implementation
This class implements Redis key-value store ( as cache driver.

It uses phpredis extension ( for communicating with Redis.
@o o Added tests 43ec9bb
@Ocramius Ocramius commented on the diff Mar 13, 2012
+ * @since 2.2
+ * @author Osman Ungur <>
+ */
+class RedisCache extends CacheProvider
+ /**
+ * @var Redis
+ */
+ private $redis;
+ /**
+ * Sets the redis instance to use.
+ *
+ * @param Redis $redis
+ */
+ public function setRedis(Redis $redis)
Ocramius Mar 13, 2012 Doctrine member

An instance of Redis is a hard dependency of this class. To avoid confusion, you should add a constructor that accepts an instance of Redis as a required parameter.

o Mar 13, 2012

I know Redis class is the hard dependency of RedisCache.
But, for avoid confusion, i used same convention with MemcacheCache driver.

Ocramius Mar 13, 2012 Doctrine member

Hmm... Yeah, makes sense, but I don't like that either... Also, modifying the MemcacheCache adapter would break BC... :(

Ocramius Mar 30, 2012 Doctrine member

Could you eventually add a __construct($redis = null) constructor and check if the passed in $redis is a Redis instance? That would probably fix also my request :)

o Apr 1, 2012

Hi Marco,
For keeping conventions same, also should add this check to MemcachedDriver.

I think we can solve this problem in another discussion/pr :)

Ocramius Apr 1, 2012 Doctrine member

Yeah, I will eventually do that :)

Doctrine member

I like it, didn't verify the tests work yet though.

@guilhermeblanco what do you think?

Doctrine member

@beberlei to me it seems good! If all tests pass, merge

o added some commits Mar 18, 2012
@o o Fixed a problem with serializer.
With this commit, cache driver uses igbinary as default serializer. Other serializer options fails with ClassMetadata like object data.
@o o Added a simple test case about serializing/unserializing objects in c…
…ache drivers.
o commented Mar 19, 2012

Hi, tests was passed for me. Under Mac OS X 10.7.3, PHP 5.4.0, Redis 2.4

 [x] Basics
 [x] Delete all
 [x] Flush all
 [x] Namespace
 [x] Get stats

Last night i committed a little serializer option fix, because phpredis SERIALIZER_PHP fails with PHP 5.4.0,
Also added a very simple test case about serializing objects.
Current tests not covers storing/fetching non-scalar (like ClassMetadata cache, QueryResult cache..) values in cache drivers.

@beberlei beberlei merged commit 6739b28 into doctrine:master Mar 30, 2012
@o o added a commit to o/doctrine2 that referenced this pull request Apr 2, 2012
@o o New cache driver definition for Doctrine running in non-dev mode and …
…cache driver is not set.

This cache driver was added with doctrine/common#109
@doctrinebot doctrinebot referenced this pull request in doctrine/doctrine2 Dec 6, 2015

DDC-1752: [GH-321] Addition for new cache driver #2402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment