SyZero.RateLimiting
10.0.0
dotnet add package SyZero.RateLimiting --version 10.0.0
NuGet\Install-Package SyZero.RateLimiting -Version 10.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SyZero.RateLimiting" Version="10.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.RateLimiting" Version="10.0.0" />
<PackageReference Include="SyZero.RateLimiting" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SyZero.RateLimiting --version 10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.RateLimiting, 10.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SyZero.RateLimiting@10.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SyZero.RateLimiting&version=10.0.0
#tool nuget:?package=SyZero.RateLimiting&version=10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.RateLimiting
限流模块:包装 .NET 内置 System.Threading.RateLimiting 与 ASP.NET Core 限流中间件,提供按 IP 的全局固定窗口策略;同时给出 IDistributedRateLimiter 抽象,可由 SyZero.Redis 提供分布式实现。
📦 安装
dotnet add package SyZero.RateLimiting
✨ 特性
- 🚦 开箱即用全局限流:默认按客户端 IP 分区、固定窗口
- 🧩
IDistributedRateLimiter抽象:进程内默认实现LocalDistributedRateLimiter,分布式实现见 SyZero.Redis - ⚙️ 可配置:窗口长度、令牌数、拒绝状态码均可在
appsettings.json调整
🚀 快速开始
1. 注册
builder.Services.AddSyZeroRateLimiting(builder.Configuration);
2. 中间件
app.UseRouting();
app.UseSyZeroRateLimiting();
app.MapControllers().RequireRateLimiting("syzero-global");
3. 业务侧使用抽象
public class LoginService
{
private readonly IDistributedRateLimiter _limiter;
public LoginService(IDistributedRateLimiter limiter) => _limiter = limiter;
public async Task<bool> TryLoginAsync(string userName)
{
if (!await _limiter.TryAcquireAsync($"login:{userName}", permitLimit: 5, window: 60))
{
throw new BusinessException("登录过于频繁,请稍后再试");
}
// ... 业务 ...
return true;
}
}
⚙️ 配置项
appsettings.json 中的 SyZeroRateLimiting 节:
| 字段 | 默认值 | 说明 |
|---|---|---|
EnableGlobal |
true |
是否启用全局策略 |
GlobalPolicyName |
syzero-global |
策略名称 |
GlobalPermitLimit |
100 |
窗口允许请求数 |
GlobalWindowSeconds |
60 |
窗口长度(秒) |
RejectionStatusCode |
429 |
拒绝时的 HTTP 状态码 |
📜 许可证
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Castle.Core (>= 5.2.1)
- Dynamitey (>= 2.0.10.189)
- ImpromptuInterface (>= 7.0.1)
- Microsoft.Extensions.DependencyModel (>= 10.0.13)
- Refit (>= 8.0.0)
- Snowflake.Core (>= 2.0.0)
- System.Linq.Dynamic.Core (>= 1.6.6)
- SyZero.Core (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SyZero.RateLimiting:
| Package | Downloads |
|---|---|
|
SyZero.Redis
SyZero-Redis |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0 | 103 | 10/23/2026 |
| 9.1.0 | 81 | 10/22/2026 |
| 1.2.0 | 84 | 10/22/2026 |
| 1.2.0-dev.1 | 49 | 10/22/2026 |