You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thrownewInvalidArgumentException(sprintf('"%s" is not a subclass of "Redis"', $class));
128
+
thrownewInvalidArgumentException(sprintf('"%s" is not a subclass of "Redis" or "Predis\Client"', $class));
110
129
} else {
111
130
thrownewInvalidArgumentException(sprintf('Class "%s" does not exist', $class));
112
131
}
@@ -139,24 +158,49 @@ protected function doFetch(array $ids)
139
158
*/
140
159
protectedfunctiondoHave($id)
141
160
{
142
-
return$this->redis->exists($id);
161
+
return(bool) $this->redis->exists($id);
143
162
}
144
163
145
164
/**
146
165
* {@inheritdoc}
147
166
*/
148
167
protectedfunctiondoClear($namespace)
149
168
{
150
-
// As documented in Redis documentation (http://redis.io/commands/keys) using KEYS
151
-
// can hang your server when it is executed against large databases (millions of items).
152
-
// Whenever you hit this scale, it is advised to deploy one Redis database per cache pool
153
-
// instead of using namespaces, so that FLUSHDB is used instead.
154
-
$lua = "local keys=redis.call('KEYS',ARGV[1]..'*') for i=1,#keys,5000 do redis.call('DEL',unpack(keys,i,math.min(i+4999,#keys))) end";
155
-
156
-
if (!isset($namespace[0])) {
157
-
$this->redis->flushDb();
158
-
} else {
159
-
$this->redis->eval($lua, array($namespace), 0);
169
+
// When using a native Redis cluster, clearing the cache cannot work and always returns false.
170
+
// Clearing the cache should then be done by any other means (e.g. by restarting the cluster).
171
+
172
+
$hosts = array($this->redis);
173
+
$evalArgs = array(array($namespace), 0);
174
+
175
+
if ($this->redisinstanceof \Predis\Client) {
176
+
$evalArgs = array(0, $namespace);
177
+
178
+
$connection = $this->redis->getConnection();
179
+
if ($connectioninstanceof PredisCluster) {
180
+
$hosts = array();
181
+
foreach ($connectionas$c) {
182
+
$hosts[] = new \Predis\Client($c);
183
+
}
184
+
} elseif ($connectioninstanceof RedisCluster) {
185
+
returnfalse;
186
+
}
187
+
} elseif ($this->redisinstanceof \RedisArray) {
188
+
foreach ($this->redis->_hosts() as$host) {
189
+
$hosts[] = $this->redis->_instance($host);
190
+
}
191
+
} elseif ($this->redisinstanceof \RedisCluster) {
192
+
returnfalse;
193
+
}
194
+
foreach ($hostsas$host) {
195
+
if (!isset($namespace[0])) {
196
+
$host->flushDb();
197
+
} else {
198
+
// As documented in Redis documentation (http://redis.io/commands/keys) using KEYS
199
+
// can hang your server when it is executed against large databases (millions of items).
200
+
// Whenever you hit this scale, it is advised to deploy one Redis database per cache pool
201
+
// instead of using namespaces, so that FLUSHDB is used instead.
202
+
$host->eval("local keys=redis.call('KEYS',ARGV[1]..'*') for i=1,#keys,5000 do redis.call('DEL',unpack(keys,i,math.min(i+4999,#keys))) end", $evalArgs[0], $evalArgs[1]);
203
+
}
160
204
}
161
205
162
206
returntrue;
@@ -194,12 +238,36 @@ protected function doSave(array $values, $lifetime)
194
238
return$failed;
195
239
}
196
240
if ($lifetime > 0) {
197
-
$this->redis->multi(\Redis::PIPELINE);
198
-
foreach ($serializedas$id => $value) {
199
-
$this->redis->setEx($id, $lifetime, $value);
200
-
}
201
-
if (!$this->redis->exec()) {
202
-
returnfalse;
241
+
if ($this->redisinstanceof \Predis\Client) {
242
+
$pipe = $this->redis->pipeline();
243
+
foreach ($serializedas$id => $value) {
244
+
$pipe->setEx($id, $lifetime, $value);
245
+
}
246
+
if (!$pipe->execute()) {
247
+
returnfalse;
248
+
}
249
+
} elseif ($this->redisinstanceof \RedisArray) {
250
+
$redis = array();
251
+
foreach ($serializedas$id => $value) {
252
+
if (!isset($redis[$h = $this->redis->_target($id)])) {
0 commit comments