Skip to content

Commit 4d76935

Browse files
committed
Merge pull request tedious#172 from Jimdo/make_redis_array_options_available_in_stash_against_master
Make redis array options available in stash
2 parents 3c7dcb2 + cf0cc32 commit 4d76935

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

src/Stash/Driver/Redis.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ class Redis implements DriverInterface
4545
*/
4646
protected $keyCache = array();
4747

48+
protected $redisArrayOptionNames = array(
49+
"previous",
50+
"function",
51+
"distributor",
52+
"index",
53+
"autorehash",
54+
"pconnect",
55+
"retry_interval",
56+
"lazy_connect",
57+
"connect_timeout",
58+
);
59+
4860
/**
4961
* Initializes the driver.
5062
*
@@ -147,6 +159,13 @@ public function setOptions(array $options = array())
147159

148160
} else {
149161

162+
$redisArrayOptions = array();
163+
foreach ($this->redisArrayOptionNames as $optionName) {
164+
if (array_key_exists($optionName, $options)) {
165+
$redisArrayOptions[$optionName] = $options[$optionName];
166+
}
167+
}
168+
150169
$serverArray = array();
151170
foreach ($servers as $server) {
152171
$serverString = $server['server'];
@@ -156,7 +175,7 @@ public function setOptions(array $options = array())
156175
$serverArray[] = $serverString;
157176
}
158177

159-
$redis = new \RedisArray($serverArray);
178+
$redis = new \RedisArray($serverArray, $redisArrayOptions);
160179
}
161180

162181
// select database

tests/Stash/Test/Driver/AbstractDriverTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ protected function setUp()
6565
}
6666
}
6767

68-
protected function getFreshDriver()
68+
protected function getFreshDriver(array $options = null)
6969
{
7070
$driverClass = $this->driverClass;
71-
$options = $this->getOptions();
71+
72+
if ($options === null) {
73+
$options = $this->getOptions();
74+
}
7275

7376
if (!$driverClass::isAvailable()) {
7477
return false;

tests/Stash/Test/Driver/RedisArrayTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,50 @@ public function itShouldConstructARedisArray()
6464

6565
$this->assertInstanceOf('\RedisArray', $redisArray);
6666
}
67+
68+
/**
69+
* @test
70+
*/
71+
public function itShouldPassOptionsToRedisArray()
72+
{
73+
$redisArrayOptions = array(
74+
"previous" => "something",
75+
"function" => function ($key) { return $key; },
76+
"distributor" => function ($key) { return 0; },
77+
"index" => "something",
78+
"autorehash" => "something",
79+
"pconnect" => "something",
80+
"retry_interval" => "something",
81+
"lazy_connect" => "something",
82+
"connect_timeout" => "something",
83+
);
84+
85+
$driverOptions = array_merge(
86+
$this->getOptions(),
87+
$redisArrayOptions
88+
);
89+
90+
if (!extension_loaded('uopz')) {
91+
$this->markTestSkipped('uopz extension is necessarry in order to stub "new".');
92+
}
93+
94+
uopz_backup('\RedisArray', '__construct');
95+
96+
$self = $this;
97+
uopz_function(
98+
'\RedisArray',
99+
'__construct',
100+
function ($serverArray, $actualRedisArrayOptions) use ($self, $redisArrayOptions) {
101+
$self->assertEquals(
102+
$redisArrayOptions,
103+
$actualRedisArrayOptions
104+
);
105+
}
106+
);
107+
108+
$this->getFreshDriver($driverOptions);
109+
110+
uopz_restore('\RedisArray', '__construct');
111+
}
112+
67113
}

tests/travis/php_setup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ else
3333
rm -Rf phpredis
3434
echo "Finished installing phpredis extension."
3535

36+
echo ""
37+
echo "******************************"
38+
echo "Installing uopz extension if possible (PHP >=5.4)."
39+
echo "******************************"
40+
set +e
41+
pecl install uopz
42+
set -e
43+
echo "Finished installing uopz extension."
44+
3645
echo ""
3746
echo "*********************"
3847
echo "Updating php.ini file"

0 commit comments

Comments
 (0)