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

[Cache] Dont use Redis connection when not required #18659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function deleteItems(array $keys)

$ok = true;

// When bulk-save failed, retry each item individually
// When bulk-delete failed, retry each item individually
foreach ($ids as $key => $id) {
try {
$e = null;
Expand Down
26 changes: 16 additions & 10 deletions 26 src/Symfony/Component/Cache/Adapter/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class RedisAdapter extends AbstractAdapter

public function __construct(\Redis $redisConnection, $namespace = '', $defaultLifetime = 0)
{
$this->redis = $redisConnection;

if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
}
$this->redis = $redisConnection;

parent::__construct($namespace, $defaultLifetime);
}
Expand All @@ -36,13 +35,15 @@ public function __construct(\Redis $redisConnection, $namespace = '', $defaultLi
*/
protected function doFetch(array $ids)
{
$values = $this->redis->mget($ids);
$index = 0;
$result = [];

foreach ($ids as $id) {
if (false !== $value = $values[$index++]) {
$result[$id] = unserialize($value);
$result = array();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is for Sf 3.1 brackets were great, isn't it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nek- our policy is to not use them, to keep consistency in the codebase (and we cannot convert the whole codebase to the short array syntax, as we will need to merge 2.8 into 3.x during 3 years, and we don't want git conflicts each time we change a line dealing with an array)


if ($ids) {
$values = $this->redis->mget($ids);
$index = 0;
foreach ($ids as $id) {
if (false !== $value = $values[$index++]) {
$result[$id] = unserialize($value);
}
}
}

Expand Down Expand Up @@ -80,7 +81,9 @@ protected function doClear($namespace)
*/
protected function doDelete(array $ids)
{
$this->redis->del($ids);
if ($ids) {
$this->redis->del($ids);
}

return true;
}
Expand All @@ -101,6 +104,9 @@ protected function doSave(array $values, $lifetime)
}
}

if (!$serialized) {
return $failed;
}
if ($lifetime > 0) {
$pipe = $this->redis->multi(\Redis::PIPELINE);
foreach ($serialized as $id => $value) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.