# @fightmegg/riot-rate-limiter 中文文档

规范地址：https://npmcn.com/package/%40fightmegg/riot-rate-limiter/

版本：0\.0\.23
npm 元数据更新时间：2025-07-28T18:53:13.705Z
中文译文更新时间：2026-11-14T18:04:48.207Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40fightmegg/riot-rate-limiter
原文对照：https://npmcn.com/package/%40fightmegg/riot-rate-limiter/?lang=original
项目主页：https://github.com/fightmegg/riot-rate-limiter#readme
源码仓库：https://github.com/fightmegg/riot-rate-limiter

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：81.4 kB，29 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：5 个
- 首次发布：2020-09-09T12:01:03.405Z
- 最新版本发布：2025-07-28T18:53:13.514Z
- 近 30 天下载量：2642（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：25（近 12 个月 0 个）

## 中文简介

暴动游戏 API 的限速器

## 安装

```sh
npm install @fightmegg/riot-rate-limiter
```

也可以使用：`pnpm add @fightmegg/riot-rate-limiter`、`yarn add @fightmegg/riot-rate-limiter`、`bun add @fightmegg/riot-rate-limiter`

## README

# 暴动率限制器

[![Version](https://img.shields.io/npm/v/@fightmegg/riot-rate-limiter.svg)](https://www.npmjs.com/package/@fightmegg/riot-rate-limiter) [![Downloads](https://img.shields.io/npm/dm/@fightmegg/riot-rate-limiter.svg)](https://www.npmjs.com/package/@fightmegg/riot-rate-limiter) [![CircleCI](https://circleci.com/gh/fightmegg/riot-rate-limiter/tree/master.svg?style=svg)](https://circleci.com/gh/fightmegg/riot-rate-limiter/tree/master)

> 节点JS 利率限制器 [暴动游戏 API](https://developer.riotgames.com/)

**[维基](https://github.com/fightmegg/riot-rate-limiter/wiki)**

### 特征

-   100%的终点覆盖率
-   **展开** 基于费率限制符
-   [请求同步](https://github.com/fightmegg/riot-rate-limiter/wiki/Request-Synchronization)
-   [请求确定优先次序](https://github.com/fightmegg/riot-rate-limiter/wiki/Request-Priorities)
-   [429个答复](https://github.com/fightmegg/riot-rate-limiter/wiki/429-Reponses) 正在重试
-   [同时提出的请求](https://github.com/fightmegg/riot-rate-limiter/wiki/Concurrency)
-   [429 重试限制](https://github.com/fightmegg/riot-rate-limiter/wiki/Max-Retries)
-   [多事件/集群](https://github.com/fightmegg/riot-rate-limiter/wiki/Multi-Instance---Cluster-\(Redis\)) 支助
-   专门为 [暴动游戏利率限制](https://web.archive.org/web/20190629194440/https://developer.riotgames.com/rate-limiting.html)

## 目录

-   [暴动率限制器](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-riot-rate-limiter)
    -   [特征](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-features)
    -   [目录](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-contents)
    -   [安装](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-installation)
    -   [使用量](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-usage)
    -   [API 密码](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-api)
        -   [`constructor`](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-constructor)
        -   [`.execute`](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-execute)
        -   [`.rateLimiters`](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-ratelimiters)
    -   [帮助者](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-helpers)
        -   [提取区域](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-extractregion)
        -   [提取方法](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-extractmethod)
        -   [方法和住房](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-methods--host)
    -   [调试](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-debugging)
    -   [测试](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-testing)
    -   [维护者](https://npmcn.com/package/%40fightmegg/riot-rate-limiter/#readme-maintainers)

## 安装

```shell
$ npm install @fightmegg/riot-rate-limiter
```

## 使用量

```ts
import { RiotRateLimiter } from "@fightmegg/riot-rate-limiter";

const limiter = new RiotRateLimiter();

// async await
const response = await limiter.execute({
  url: "https://euw1.api.riotgames.com/lol/some/method",
  options: {
    headers: {
      "X-Riot-Token": "...",
    },
  },
});

// Promises
limiter
  .execute({
    url: "https://euw1.api.riotgames.com/lol/some/method",
    options: {
      headers: {
        "X-Riot-Token": "...",
      },
    },
  })
  .then((response) => {
    // ...
  });
```

## API 密码

#### `constructor`

```ts
new RiotRateLimiter({
  debug: boolean = false,
  concurrency: number = 1,
  retryAfterDefault: number = 5000,
  retryCount: number = 4,
  datastore: 'local' | 'ioredis' = 'local'
  redis?: RedisConnectionOptions | RedisConnectionString = null
});
```

#### `.execute`

此库使用 [节点比对](https://github.com/node-fetch/node-fetch) {\\fn黑体\\fs22\\bord1\\shad0\\3aHBE\\4aH00\\fscx67\\fscy66\\2cHFFFFFF\\3cH808080}在兜帽下面 用来提出要求 这个 `.execute` 方法从字面上传递所有给 **节点比对**因此,你可以改变诸如 _方法_, (中文(简体) ), _页眉_ 包括:.

任何不是2xx或429的反应都会被扔出,必须被抓住.

我们会的 **自动重试** `429` 回复,直到重试时止 `4`),利用 `Retry-After` 头来尊重API.

```ts
limiter.execute({
  url: RequestInfo,
  options: RequestInit,
},
  jobOptions?: Bottleneck.JobOptions
);
```

第二个参数是可选的,允许您指定 [任务选项](https://github.com/SGrondin/bottleneck#job-options) 例如工作优先级和用于日志识别的独特ID。 工作重量不能从 `1` 不管你通过什么.

#### `.rateLimiters`

这是一个 **地图** 在创建的所有限速器中,我们至少为 **区域** ,然后,每份申请至少有1份费率限制 **方法** 在那个区域下面.

我们用图书馆 [圆顶](https://github.com/SGrondin/bottleneck) 作为我们的费率限制器,它支持连锁费率限制器,这意味着父母的费率限制器总是受到子女的尊重.

您可以访问 **区域** 费率限制通过: `limiter.rateLimiters[region].main` 你可以访问 **方法** 费率限制通过: `limiter.rateLimiters[region][method].main`

## 帮助者

我们还提供了一些辅助函数和对象.

#### 提取区域

这可以从您的 URL 中提取区域或平台 :

```ts
import { extractRegion } from "@fightmegg/riot-rate-limiter";

extractRegion("https://na1.api.riotgames.com/method"); // returns na1
```

#### 提取方法

这可以从您的 URL 中提取方法 :

```ts
import { extractMethod } from "@fightmegg/riot-rate-limiter";

extractMethod(
  "https://na1.api.riotgames.com/lol/champion-mastery/v4/scores/by-summoner/12345"
); // returns 'CHAMPION_MASTERY.GET_CHAMPION_MASTERY_SCORE'
```

#### 方法和住房

对于那些想要建立 `RiotGamesAPI` 此速率限制器上方的库, 我们导出两个名为对象 [方法和住房](https://github.com/fightmegg/riot-rate-limiter/blob/master/%40types/index.ts#L58)。 您可以使用这些导出为您创建 URL, 如下所示:

```ts
import { compile } from "path-to-regexp";
import { HOST, METHODS } from "@fightmegg/riot-rate-limiter";

const createHost = compile(HOST, { encode: encodeURIComponent });
const createPath = compile(METHODS.ACCOUNT.GET_BY_PUUID, {
  encode: encodeURIComponent,
});

const url = `https://${createHost({ platformId: "euw1" })}${createPath({
  puuid: "12345",
})}`;
```

## 调试

如果你想看到想要的 速率限制器正在做,我们使用 [调试](https://github.com/visionmedia/debug) 用于记录的模块。 简单的运行您的应用程序:

```shell
DEBUG=riotratelimiter* node ...
```

## 测试

单位测试 : `npm test`

E2E测试: `npm run test:e2e`

## 维护者

[@olliejennings (英语)](https://github.com/olliejennings)

## 常见问题

### @fightmegg/riot-rate-limiter 是什么？

暴动游戏 API 的限速器

### 如何安装 @fightmegg/riot-rate-limiter？

在项目目录运行 npm install @fightmegg/riot-rate-limiter，或使用 pnpm add / yarn add / bun add。

### @fightmegg/riot-rate-limiter 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @fightmegg/riot-rate-limiter 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @fightmegg/riot-rate-limiter 可以商用吗？

@fightmegg/riot-rate-limiter 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @fightmegg/riot-rate-limiter 的下载量有多少？

根据 npm 官方下载统计，@fightmegg/riot-rate-limiter 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,642 次，日均约 88 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @fightmegg/riot-rate-limiter 还在维护吗？

最新版本 0\.0\.23 发布于 2025/07/29（1\.3 年前）；至今共发布 25 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/09/09。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

