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 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
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);
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