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