diff --git a/src/Stash/Driver/Redis.php b/src/Stash/Driver/Redis.php index f8371c5e..b5158551 100644 --- a/src/Stash/Driver/Redis.php +++ b/src/Stash/Driver/Redis.php @@ -45,6 +45,18 @@ class Redis implements DriverInterface */ protected $keyCache = array(); + protected $redisArrayOptionNames = array( + "previous", + "function", + "distributor", + "index", + "autorehash", + "pconnect", + "retry_interval", + "lazy_connect", + "connect_timeout", + ); + /** * Initializes the driver. * @@ -147,6 +159,13 @@ public function setOptions(array $options = array()) } else { + $redisArrayOptions = array(); + foreach ($this->redisArrayOptionNames as $optionName) { + if (array_key_exists($optionName, $options)) { + $redisArrayOptions[$optionName] = $options[$optionName]; + } + } + $serverArray = array(); foreach ($servers as $server) { $serverString = $server['server']; @@ -156,7 +175,7 @@ public function setOptions(array $options = array()) $serverArray[] = $serverString; } - $redis = new \RedisArray($serverArray); + $redis = new \RedisArray($serverArray, $redisArrayOptions); } // select database diff --git a/tests/Stash/Test/Driver/AbstractDriverTest.php b/tests/Stash/Test/Driver/AbstractDriverTest.php index 3312e183..59df4815 100644 --- a/tests/Stash/Test/Driver/AbstractDriverTest.php +++ b/tests/Stash/Test/Driver/AbstractDriverTest.php @@ -65,10 +65,13 @@ protected function setUp() } } - protected function getFreshDriver() + protected function getFreshDriver(array $options = null) { $driverClass = $this->driverClass; - $options = $this->getOptions(); + + if ($options === null) { + $options = $this->getOptions(); + } if (!$driverClass::isAvailable()) { return false; diff --git a/tests/Stash/Test/Driver/RedisArrayTest.php b/tests/Stash/Test/Driver/RedisArrayTest.php index fbc7524d..eafe04f6 100644 --- a/tests/Stash/Test/Driver/RedisArrayTest.php +++ b/tests/Stash/Test/Driver/RedisArrayTest.php @@ -64,4 +64,50 @@ public function itShouldConstructARedisArray() $this->assertInstanceOf('\RedisArray', $redisArray); } + + /** + * @test + */ + public function itShouldPassOptionsToRedisArray() + { + $redisArrayOptions = array( + "previous" => "something", + "function" => function ($key) { return $key; }, + "distributor" => function ($key) { return 0; }, + "index" => "something", + "autorehash" => "something", + "pconnect" => "something", + "retry_interval" => "something", + "lazy_connect" => "something", + "connect_timeout" => "something", + ); + + $driverOptions = array_merge( + $this->getOptions(), + $redisArrayOptions + ); + + if (!extension_loaded('uopz')) { + $this->markTestSkipped('uopz extension is necessarry in order to stub "new".'); + } + + uopz_backup('\RedisArray', '__construct'); + + $self = $this; + uopz_function( + '\RedisArray', + '__construct', + function ($serverArray, $actualRedisArrayOptions) use ($self, $redisArrayOptions) { + $self->assertEquals( + $redisArrayOptions, + $actualRedisArrayOptions + ); + } + ); + + $this->getFreshDriver($driverOptions); + + uopz_restore('\RedisArray', '__construct'); + } + } diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 4bf3582b..492fed17 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -33,6 +33,15 @@ else rm -Rf phpredis echo "Finished installing phpredis extension." + echo "" + echo "******************************" + echo "Installing uopz extension if possible (PHP >=5.4)." + echo "******************************" + set +e + pecl install uopz + set -e + echo "Finished installing uopz extension." + echo "" echo "*********************" echo "Updating php.ini file"