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