8000 Fast multiple setEx with the pipeline transcation (RedisAdapter::doSave) by masterklavi · Pull Request #18248 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Fast multiple setEx with the pipeline transcation (RedisAdapter::doSave)
  • Loading branch information
masterklavi committed Mar 21, 2016
commit ff8b8822073d0ebf430394a7873b1eee4916eea9
20 changes: 11 additions & 9 deletions src/Symfony/Component/Cache/Adapter/RedisAdapter.php
Original file line number Diff line number Diff line change
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);
Copy link
Member

Choose a reason for hiding this comment

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

missing \: \Redis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, fixed.

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