Skip to content

Commit

Permalink
bug #18248 Fast multiple setEx with the pipeline transcation (RedisAd…
Browse files Browse the repository at this point in the history
…apter::doSave) (masterklavi)

This PR was squashed before being merged into the 3.1-dev branch (closes #18248).

Discussion
----------

Fast multiple setEx with the pipeline transcation (RedisAdapter::doSave)

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

e132763 Fast multiple setEx with the pipeline transcation (RedisAdapter::doSave)
  • Loading branch information
nicolas-grekas committed Mar 23, 2016
2 parents c7493f5 + e132763 commit abb8d64
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Symfony/Component/Cache/Adapter/RedisAdapter.php
Expand Up @@ -93,22 +93,24 @@ protected function doSave(array $values, $lifetime)
$serialized = array();
$failed = array();

foreach ($values as $id => $v) {
foreach ($values as $id => $value) {
try {
$serialized[$id] = serialize($v);
$serialized[$id] = serialize($value);
} catch (\Exception $e) {
$failed[] = $id;
}
}

if (!$this->redis->mSet($serialized)) {
return false;
}

if ($lifetime >= 1) {
foreach ($serialized as $id => $v) {
$this->redis->expire($id, $lifetime);
if ($lifetime > 0) {
$pipe = $this->redis->multi(\Redis::PIPELINE);
foreach ($serialized as $id => $value) {
$pipe->setEx($id, $lifetime, $value);
}
if (!$pipe->exec()) {
return false;
}
} elseif (!$this->redis->mSet($serialized)) {
return false;
}

return $failed;
Expand Down

0 comments on commit abb8d64

Please sign in to comment.