Table of Contents

Class RedisRateLimiter

Namespace
JD.AI.Core.Security
Assembly
JD.AI.Core.dll

Redis-backed distributed sliding window rate limiter using sorted sets. Falls back to local SlidingWindowRateLimiter if Redis is unavailable.

public sealed class RedisRateLimiter : IRateLimiter
Inheritance
RedisRateLimiter
Implements
Inherited Members

Constructors

RedisRateLimiter(IConnectionMultiplexer, ILogger<RedisRateLimiter>, int, TimeSpan?)

public RedisRateLimiter(IConnectionMultiplexer redis, ILogger<RedisRateLimiter> logger, int maxRequests = 60, TimeSpan? window = null)

Parameters

redis IConnectionMultiplexer
logger ILogger<RedisRateLimiter>
maxRequests int
window TimeSpan?

Methods

AllowAsync(string, CancellationToken)

Returns true if the request is allowed; false if rate-limited.

public Task<bool> AllowAsync(string key, CancellationToken ct = default)

Parameters

key string
ct CancellationToken

Returns

Task<bool>

CheckAsync(string, CancellationToken)

Checks the rate limit and returns detailed result with remaining quota and reset time.

public Task<RateLimitResult> CheckAsync(string key, CancellationToken ct = default)

Parameters

key string
ct CancellationToken

Returns

Task<RateLimitResult>