Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
Redis::scan 方法 迭代值不返回问题修复
  • Loading branch information
liuxin committed Dec 2, 2020
1 parent 9a0146b commit e6b3304
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/redis/src/Connection/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,41 @@ public function release(bool $force = false): void
parent::release($force);
}

/**
* @param $iterator
* @param string|null $pattern
* @param int $count
* @return array
* @throws RedisException
*/
public function scan($iterator, string $pattern = null, int $count = 0): array
{
try {
// Before event
Swoft::trigger(RedisEvent::BEFORE_COMMAND, null, 'scan', [$iterator, $pattern, $count]);

Log::profileStart('redis.%s', 'scan');
$rest = $this->client->scan($iterator, $pattern, $count);
Log::profileEnd('redis.%s', 'scan');

// After event
Swoft::trigger(RedisEvent::AFTER_COMMAND, null, 'scan', [$iterator, $pattern, $count], ['cursor'=>$iterator,'result'=>$rest]);

// Release Connection
$this->release();
return ['cursor'=>$iterator,'result'=>$rest];
} catch (Throwable $e) {
if ($this->reconnect()) {
$rest = $this->client->scan($iterator, $pattern, $count);
return ['cursor'=>$iterator,'result'=>$rest];
}

throw new RedisException(
sprintf('Redis command reconnect error(%s)', $e->getMessage())
);
}
}

/**
* @param string $key
* @param array $keys
Expand Down

0 comments on commit e6b3304

Please sign in to comment.