mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 18:30:16 +08:00
30 lines
581 B
PHP
30 lines
581 B
PHP
<?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]];
|
|
}
|
|
} |