Skip to content

Commit bae1a70

Browse files
committed
forwarding predis options directly without wrapping it
1 parent 74cbd32 commit bae1a70

File tree

3 files changed

+30
-378
lines changed

3 files changed

+30
-378
lines changed

src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php

Lines changed: 10 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use SplitIO\Component\Cache\Storage\Exception\AdapterException;
55
use SplitIO\Component\Utils as SplitIOUtils;
6-
use SplitIO\Component\Common\Context;
76

87
/**
98
* Class PRedis
@@ -26,7 +25,7 @@ public function __construct(array $options)
2625
}
2726
$_redisConfig = $this->getRedisConfiguration($options);
2827

29-
$this->client = new \Predis\Client($_redisConfig['redis'], $_redisConfig['options']);
28+
$this->client = new \Predis\Client($_redisConfig['parameters'], $_redisConfig['options']);
3029
}
3130

3231
/**
@@ -48,24 +47,6 @@ private function isValidConfigArray($nodes, $type)
4847
return null;
4948
}
5049

51-
/**
52-
* @param array $sentinels
53-
* @param array $options
54-
* @return bool
55-
* @throws AdapterException
56-
*/
57-
private function isValidSentinelConfig($sentinels, $options)
58-
{
59-
$msg = $this->isValidConfigArray($sentinels, 'sentinel');
60-
if (!is_null($msg)) {
61-
throw new AdapterException($msg);
62-
}
63-
if (!isset($options['service'])) {
64-
throw new AdapterException('Master name is required in replication mode for sentinel.');
65-
}
66-
return true;
67-
}
68-
6950
private function validateKeyHashTag($keyHashTag)
7051
{
7152
if (!is_string($keyHashTag)) {
@@ -121,83 +102,32 @@ function ($value) {
121102
if (empty($filteredArray)) {
122103
throw new AdapterException('keyHashTags size is zero after filtering valid elements.');
123104
}
124-
return $selected = $filteredArray[array_rand($filteredArray, 1)];
105+
return $filteredArray[array_rand($filteredArray, 1)];
125106
}
126107

127108

128-
/**
129-
* @param array $clusters
130-
* @return bool
131-
* @throws AdapterException
132-
*/
133-
private function isValidClusterConfig($clusters)
134-
{
135-
$msg = $this->isValidConfigArray($clusters, 'clusterNode');
136-
if (!is_null($msg)) {
137-
throw new AdapterException($msg);
138-
}
139-
return true;
140-
}
141-
142109
/**
143110
* @param mixed $options
144111
* @return array
145-
* @throws AdapterException
146112
*/
147113
private function getRedisConfiguration($options)
148114
{
149115
$redisConfigutation = array(
150-
'redis' => null,
151-
'options' => null
116+
'parameters' => (isset($options['parameters'])) ? $options['parameters'] : null,
117+
'options' => null,
152118
);
153119

154-
$parameters = (isset($options['parameters'])) ? $options['parameters'] : null;
155-
$sentinels = (isset($options['sentinels'])) ? $options['sentinels'] : null;
156-
$clusters = (isset($options['clusterNodes'])) ? $options['clusterNodes'] : null;
157120
$_options = (isset($options['options'])) ? $options['options'] : null;
158-
159-
if (isset($_options['distributedStrategy']) && isset($parameters['tls'])) {
160-
throw new AdapterException("SSL/TLS cannot be used together with sentinel/cluster yet");
161-
}
162-
163121
if ($_options && isset($_options['prefix'])) {
164122
$_options['prefix'] = self::normalizePrefix($_options['prefix']);
165123
}
166124

167-
if (isset($parameters)) {
168-
$redisConfigutation['redis'] = $parameters;
169-
} else {
170-
// @TODO remove this statement when replication will be deprecated
171-
if (isset($_options['replication'])) {
172-
Context::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
173-
if (!isset($_options['distributedStrategy'])) {
174-
$_options['distributedStrategy'] = $_options['replication'];
175-
}
176-
}
177-
if (isset($_options['distributedStrategy'])) {
178-
switch ($_options['distributedStrategy']) {
179-
case 'cluster':
180-
if ($this->isValidClusterConfig($clusters)) {
181-
$keyHashTag = $this->selectKeyHashTag($_options);
182-
$_options['cluster'] = 'redis';
183-
$redisConfigutation['redis'] = $clusters;
184-
$prefix = isset($_options['prefix']) ? $_options['prefix'] : '';
185-
$_options['prefix'] = $keyHashTag . $prefix;
186-
}
187-
break;
188-
case 'sentinel':
189-
if ($this->isValidSentinelConfig($sentinels, $_options)) {
190-
$_options['replication'] = 'sentinel';
191-
$redisConfigutation['redis'] = $sentinels;
192-
}
193-
break;
194-
default:
195-
throw new AdapterException("Wrong configuration of redis 'distributedStrategy'.");
196-
}
197-
} else {
198-
throw new AdapterException("Wrong configuration of redis.");
199-
}
125+
if (isset($_options['cluster'])) {
126+
$keyHashTag = $this->selectKeyHashTag($_options);
127+
$prefix = isset($_options['prefix']) ? $_options['prefix'] : '';
128+
$_options['prefix'] = $keyHashTag . $prefix;
200129
}
130+
201131
$redisConfigutation['options'] = $_options;
202132
return $redisConfigutation;
203133
}
@@ -254,8 +184,7 @@ public function getKeys($pattern = '*')
254184
$prefix = $this->client->getOptions()->__get("prefix")->getPrefix();
255185
}
256186

257-
if ($this->client->getOptions()->__isset("distributedStrategy") &&
258-
$this->client->getOptions()->__get("distributedStrategy") == "cluster") {
187+
if ($this->client->getOptions()->__isset("cluster")) {
259188
$keys = array();
260189
foreach ($this->client as $nodeClient) {
261190
$nodeClientKeys = $nodeClient->keys($pattern);

src/SplitIO/Sdk.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ private static function configureCache(array $options)
6767
} elseif ($cacheAdapter == 'predis') {
6868
$_options['options'] = isset($options['options']) ? $options['options'] : null;
6969
$_options['parameters'] = isset($options['parameters']) ? $options['parameters'] : null;
70-
$_options['sentinels'] = isset($options['sentinels']) ? $options['sentinels'] : null;
71-
$_options['clusterNodes'] = isset($options['clusterNodes']) ? $options['clusterNodes'] : null;
72-
$_options['distributedStrategy'] = isset($options['distributedStrategy'])
73-
? $options['distributedStrategy'] : null;
7470
} else {
7571
throw new Exception("A valid cache system is required. Given: $cacheAdapter");
7672
}

0 commit comments

Comments
 (0)