Skip to content

Commit

Permalink
fix: check
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Dec 27, 2024
1 parent d985da2 commit a9c7993
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Abuse/Adapters/TimeLimit/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function hit(string $key, int $timestamp): void
*
* @param int|null $offset
* @param int|null $limit
* @return array<string, mixed>
* @return array<string, string|false>
*/
public function getLogs(?int $offset = null, ?int $limit = 25): array
{
Expand All @@ -93,10 +93,26 @@ public function getLogs(?int $offset = null, ?int $limit = 25): array
$pattern = self::NAMESPACE . '__*';

do {
[$cursor, $keys] = $this->redis->scan($cursor, $pattern, $limit);
/** @var array{0: string|false, 1: array<int, string>} */
$result = $this->redis->scan($cursor, $pattern, $limit);

if ($result === false) {
break;
}

[$newCursor, $keys] = $result;
$cursor = (int)$newCursor;

if (!empty($keys)) {
/** @var array<string|false> */
$values = $this->redis->mget($keys);
$matches = array_merge($matches, array_combine($keys, $values));
if ($values !== false) {
/** @var array<string, string|false> */
$combinedArray = array_combine($keys, $values);
if ($combinedArray !== false) {
$matches = array_merge($matches, $combinedArray);
}
}
}
} while ($cursor > 0 && (!$limit || count($matches) < $limit));

Expand Down

0 comments on commit a9c7993

Please sign in to comment.