feat : common redis cache and common logger

This commit is contained in:
2025-09-14 15:58:45 +08:00
parent 48ad2ebd1b
commit 0db9995c19
15 changed files with 640 additions and 14 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Cache\Redis\Lua;
use App\Cache\Redis\BaseScript;
class RateLimit extends BaseScript
{
/**
* @return string
*/
public function getName(): string
{
return 'rate_limit';
}
/**
* 限流
* @param string $key
* @param int $limit
* @param int $window
* @return array
*/
public function check(string $key, int $limit, int $window): array
{
$result = $this->run([$key], [$limit, $window]);
if (!$result) return [];
return [(bool)$result[0], (int)$result[1]];
}
}