Skip to content

Commit

Permalink
Merge pull request #172 from Jimdo/make_redis_array_options_available…
Browse files Browse the repository at this point in the history
…_in_stash_against_master

Make redis array options available in stash
  • Loading branch information
tedivm committed May 31, 2014
2 parents 3c7dcb2 + cf0cc32 commit 4d76935
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/Stash/Driver/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'];
Expand All @@ -156,7 +175,7 @@ public function setOptions(array $options = array())
$serverArray[] = $serverString;
}

$redis = new \RedisArray($serverArray);
$redis = new \RedisArray($serverArray, $redisArrayOptions);
}

// select database
Expand Down
7 changes: 5 additions & 2 deletions tests/Stash/Test/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions tests/Stash/Test/Driver/RedisArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}
9 changes: 9 additions & 0 deletions tests/travis/php_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4d76935

Please sign in to comment.