mabe/ratelimit-bundle

此symfony扩展包提供了基于Redis限制请求的功能。

安装: 29

依赖: 0

建议者: 0

安全性: 0

星标: 4

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

v0.1.1 2018-10-19 02:46 UTC

This package is auto-updated.

Last update: 2024-09-13 18:37:29 UTC


README

Build Status License: MIT

RateLimitBundle

一个轻量级的symfony扩展包,用于限制指定路径的请求速率。

要求

Redis服务器

安装

步骤 1: 下载扩展包

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此扩展包的最新稳定版本

$ composer require mabe/ratelimit-bundle

此命令要求您全局安装了Composer,具体请参考Composer文档中的安装章节

步骤 2: 启用扩展包

然后,通过将其添加到项目app/AppKernel.php文件中已注册的扩展包列表中来启用扩展包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Mabe\RateLimitBundle\MabeRateLimitBundle(),
        );

        // ...
    }

    // ...
}

步骤 3: 配置

在config.yml中添加您想要的配置。

rate_limit:
    enabled: true
    redis:
        # Your redis server IP (default localhost) and database
        host: 127.0.0.1
        database: 5
    paths:
        # Path to put restriction on
        - path: /api/test
        # Times the path can be accessed
          limit: 1
        # Period in seconds
          period: 5
        # Redis identifier for storing keys (ip or username currently available)
          identifier: ip

运行测试

./vendor/bin/simple-phpunit