Redis + RateLimiting

This commit is contained in:
2024-04-23 20:14:32 +02:00
parent c715dadb11
commit 6c39c292b0
15 changed files with 330 additions and 48 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace Core\Objects;
class RateLimitRule {
const SECOND = 0;
const MINUTE = 1;
const HOUR = 2;
private int $count;
private int $perSecond;
public function __construct(int $count, int $time, int $unit) {
$this->count = $count;
$this->perSecond = $time;
if ($unit === self::HOUR) {
$this->perSecond *= 60 * 60;
} else if ($unit === self::MINUTE) {
$this->perSecond *= 60;
}
}
public function getCount(): int {
return $this->count;
}
public function getWindow(): int {
return $this->perSecond;
}
}