定制 bud/rate-limit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bud/rate-limit

最新稳定版本:v3.1.0

Composer 安装命令:

composer require bud/rate-limit

包简介

Redis based rate limiter in the hyperf framework

README 文档

README

适配 hyperf 框架的请求频率限流器,基于 Hyperf\Redis\Redis 实现

安装

composer require bud/rate-limit

注解使用

以下代码仅做用法展示

<?php
declare(strict_types=1);

namespace App\Controller;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use Bud\RateLimit\Annotation\RateLimitAnnotation;

#[AutoController(prefix: "test")]
class TestController
{
    /**
     * 20秒内仅允许请求一次
     */
    #[RequestMapping(path: "", methods: "get"),RateLimitAnnotation('test', 20, 1)]
    public function index()
    {
        return [
            'key' => 'rate_limit:App\Controller\IndexController:index:test'
        ];
    }

    /**
     * 相同路径参数一分钟仅允许访问一次
     */
    #[RequestMapping(path: "{id}", methods: "get"),RateLimitAnnotation('test:{id}', 60, 1)]
    public function info(int $id)
    {
        return [
            'key' => "rate_limit:App\Controller\IndexController:info:test:$id"
        ];
    }
}

静态方法使用

    /**
     * @param string $key 限流键
     * @param int $unit_time 单位时间(秒)默认(60)秒
     * @param int $max_number 最大访问次数 默认60次,即一秒一次
    */
    \Zeno\RateLimit\RateLimit::checkLimit(string $key, int $unit_time = 60, int $max_number = 60)

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-22