Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae1baac

Browse files
committed
bug #18659 [Cache] Dont use Redis connection when not required (nicolas-grekas)
This PR was merged into the 3.1-dev branch. Discussion ---------- [Cache] Dont use Redis connection when not required | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 1165459 [Cache] Dont use Redis connection when not required
2 parents 2d4df16 + 1165459 commit ae1baac

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function deleteItems(array $keys)
227227

228228
$ok = true;
229229

230-
// When bulk-save failed, retry each item individually
230+
// When bulk-delete failed, retry each item individually
231231
foreach ($ids as $key => $id) {
232232
try {
233233
$e = null;

src/Symfony/Component/Cache/Adapter/RedisAdapter.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ class RedisAdapter extends AbstractAdapter
2222

2323
public function __construct(\Redis $redisConnection, $namespace = '', $defaultLifetime = 0)
2424
{
25-
$this->redis = $redisConnection;
26-
2725
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
2826
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
2927
}
28+
$this->redis = $redisConnection;
3029

3130
parent::__construct($namespace, $defaultLifetime);
3231
}
@@ -36,13 +35,15 @@ public function __construct(\Redis $redisConnection, $namespace = '', $defaultLi
3635
*/
3736
protected function doFetch(array $ids)
3837
{
39-
$values = $this->redis->mget($ids);
40-
$index = 0;
41-
$result = [];
42-
43-
foreach ($ids as $id) {
44-
if (false !== $value = $values[$index++]) {
45-
$result[$id] = unserialize($value);
38+
$result = array();
39+
40+
if ($ids) {
41+
$values = $this->redis->mget($ids);
42+
$index = 0;
43+
foreach ($ids as $id) {
44+
if (false !== $value = $values[$index++]) {
45+
$result[$id] = unserialize($value);
46+
}
4647
}
4748
}
4849

@@ -80,7 +81,9 @@ protected function doClear($namespace)
8081
*/
8182
protected function doDelete(array $ids)
8283
{
83-
$this->redis->del($ids);
84+
if ($ids) {
85+
$this->redis->del($ids);
86+
}
8487

8588
return true;
8689
}
@@ -101,6 +104,9 @@ protected function doSave(array $values, $lifetime)
101104
}
102105
}
103106

107+
if (!$serialized) {
108+
return $failed;
109+
}
104110
if ($lifetime > 0) {
105111
$pipe = $this->redis->multi(\Redis::PIPELINE);
106112
foreach ($serialized as $id => $value) {

0 commit comments

Comments
 (0)