Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1165459

Browse filesBrowse files
[Cache] Dont use Redis connection when not required
1 parent f2228d5 commit 1165459
Copy full SHA for 1165459

File tree

Expand file treeCollapse file tree

2 files changed

+17
-11
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-11
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/RedisAdapter.php
+16-10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.