mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 19:27:48 +08:00
feat : common redis cache and common logger
This commit is contained in:
30
app/Cache/Redis/Lua/RateLimit.php
Normal file
30
app/Cache/Redis/Lua/RateLimit.php
Normal 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]];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user