Skip to content

Commit

Permalink
Update: 优化实现
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX authored Apr 6, 2024
1 parent e25bfab commit f653596
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Cache/Handler/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,20 @@ public function clear(): bool
*/
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
foreach ($keys as &$key)
$parsedKeys = [];
foreach ($keys as $i => $key)
{
$key = $this->parseKey($key);
$parsedKeys[$i] = $this->parseKey($key);
}
unset($key);
$mgetResult = ImiRedis::use(static fn (\Imi\Redis\RedisHandler $redis) => $redis->mget($keys), $this->poolName, true);
$mgetResult = ImiRedis::use(static fn (\Imi\Redis\RedisHandler $redis) => $redis->mget($parsedKeys), $this->poolName, true);
$result = [];
if ($mgetResult)
{
foreach ($mgetResult as $i => $v)
{
$key = $keys[$i];

if ($this->prefix && str_starts_with((string) $key, $this->prefix))
{
$key = substr((string) $key, \strlen($this->prefix));
}

if (false === $v)
{
$result[$key] = $default;
Expand Down

0 comments on commit f653596

Please sign in to comment.