8000 Fast multiple setEx with the pipeline transcation (RedisAdapter::doSave) · symfony/symfony@e132763 · GitHub
[go: up one dir, main page]

Skip to content

Commit e132763

Browse files
masterklavinicolas-grekas
authored andcommitted
Fast multiple setEx with the pipeline transcation (RedisAdapter::doSave)
1 parent 003507d commit e132763

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/Symfony/Component/Cache/Adapter/RedisAdapter.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,24 @@ protected function doSave(array $values, $lifetime)
9393
$serialized = array();
9494
$failed = array();
9595

96-
foreach ($values as $id => $v) {
96+
foreach ($values as $id => $value) {
9797
try {
98-
$serialized[$id] = serialize($v);
98+
$serialized[$id] = serialize($value);
9999
} catch (\Exception $e) {
100100
$failed[] = $id;
101101
}
102102
}
103103

104-
if (!$this->redis->mSet($serialized)) {
105-
return false;
106-
}
107-
108-
if ($lifetime >= 1) {
109-
foreach ($serialized as $id => $v) {
110-
$this->redis->expire($id, $lifetime);
104+
if ($lifetime > 0) {
105+
$pipe = $this->redis->multi(\Redis::PIPELINE);
106+
foreach ($serialized as $id => $value) {
107+
$pipe->setEx($id, $lifetime, $value);
111108
}
109+
if (!$pipe->exec()) {
110+
return false;
111+
}
112+
} elseif (!$this->redis->mSet($serialized)) {
113+
return false;
112114
}
113115

114116
return $failed;

0 commit comments

Comments
 (0)
0