Skip to content
Open
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
15 changes: 10 additions & 5 deletions system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,20 @@ public function save(string $key, mixed $value, int $ttl = 60): bool
return false;
}

if (! $this->redis->hmset($key, ['__ci_type' => $dataType, '__ci_value' => $value]) instanceof Status) {
return false;
}
$fields = ['__ci_type' => $dataType, '__ci_value' => $value];

if ($ttl !== 0) {
$this->redis->expireat($key, Time::now()->getTimestamp() + $ttl);
// Send HMSET and EXPIREAT in a single round trip.
$expiresAt = Time::now()->getTimestamp() + $ttl;
$results = $this->redis->pipeline(static function ($pipe) use ($key, $fields, $expiresAt): void {
$pipe->hmset($key, $fields);
$pipe->expireat($key, $expiresAt);
});

return is_array($results) && ($results[0] ?? null) instanceof Status;
}

return true;
return $this->redis->hmset($key, $fields) instanceof Status;
}

public function delete(string $key): bool
Expand Down
19 changes: 14 additions & 5 deletions system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,24 @@ public function save(string $key, mixed $value, int $ttl = 60): bool
return false;
}

if (! $this->redis->hMset($key, ['__ci_type' => $dataType, '__ci_value' => $value])) {
return false;
}
$fields = ['__ci_type' => $dataType, '__ci_value' => $value];

if ($ttl !== 0) {
$this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl);
// Send HMSET and EXPIREAT in a single round trip.
$pipeline = $this->redis->multi(Redis::PIPELINE);

if ($pipeline === false) {
return false;
}

$pipeline->hMset($key, $fields);
$pipeline->expireAt($key, Time::now()->getTimestamp() + $ttl);
$results = $pipeline->exec();

return is_array($results) && (bool) ($results[0] ?? false);
}

return true;
return (bool) $this->redis->hMset($key, $fields);
}

public function delete(string $key): bool
Expand Down
Loading