Skip to content

Commit

Permalink
fix cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Mar 12, 2024
1 parent 6f44bd8 commit 126cadf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Abuse/Adapters/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,24 @@ public function cleanup(string $datetime): bool
// TODO
$iterator = NULL;
while($iterator !== 0) {
$keys = $this->redis->scan($iterator, self::NAMESPACE . ':*:' . $datetime);
var_dump($keys);
$keys = $this->redis->scan($iterator, self::NAMESPACE . ':*:*', 1000);
$keys = $this->filterKeys($keys, $datetime);
$this->redis->del($keys);
}
return true;
}

protected function filterKeys(array $keys, int $timestamp): array {
$filteredKeys = [];
foreach ($keys as $key) {
$parts = explode(':', $key);
$keyTimestamp = (int)end($parts); // Assuming the last part is always the timestamp
if ($keyTimestamp < $timestamp) {
$filteredKeys[] = $key;
}
}
return $filteredKeys;
}


}
1 change: 1 addition & 0 deletions tests/Abuse/AbuseRedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function testCleanup(): void
$logs = $this->abuse->getLogs(0, 10);
$this->assertEquals(3, \count($logs));

sleep(5);
// Delete the log
$interval = DateInterval::createFromDateString(1 . ' seconds');
$status = $this->abuse->cleanup((new \DateTime())->sub($interval)->getTimestamp());
Expand Down

0 comments on commit 126cadf

Please sign in to comment.