Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nimanikoo/Dotnet-RateLimiter/llms.txt
Use this file to discover all available pages before exploring further.
RedisRateLimiter is the heart of the distributed rate limiting system. It wraps a single atomic Lua script that runs inside Redis, which means the counter increment and the limit check happen in one round-trip with no race conditions — even across multiple application instances or pods. Every inbound HTTP request that carries a [RedisRateLimit] attribute is evaluated by this service before it reaches your controller logic.
Namespace
Class Declaration
virtual, making it straightforward to mock or subclass in unit and integration tests without requiring any additional abstraction layer.
Constructor
IConnectionMultiplexer and stores it as the private IDatabase _db field used by all subsequent calls.
The StackExchange.Redis multiplexer that manages the connection pool to your Redis
server. Registered as a singleton by
AddCustomRateLimiter and injected automatically
by the ASP.NET Core DI container.Method: IsAllowedAsync
maxRequests and returns true when the request is within quota or false when the limit has been exceeded.
The composite rate-limit identifier, typically constructed by the middleware as
{userType}:{identityKey}:{path} (e.g. user:42:/api/weather or
guest:192.168.1.1:/api/weather). The method internally prepends rate_limit: so
the final Redis key becomes rate_limit:{key}.The maximum number of requests permitted within a single window. Sourced directly from
RedisRateLimitAttribute.MaxRequests on the matched endpoint.The duration of the rate-limit window. Converted to whole seconds before being passed
to the Lua script as the Redis
EXPIRE value. Sourced from
RedisRateLimitAttribute.WindowSeconds.true if the request is within the allowed quota; false if the rate limit has been
exceeded for this key in the current window.Full Implementation
The Lua script sets the TTL only when the counter reaches
1 (i.e. the very first
request in a new window). This ensures the window starts at the moment of the first
request and does not slide on every subsequent call — this is a fixed window
semantic at the Redis level.Redis Key Format
| Segment | Example value |
|---|---|
| Prefix | rate_limit: |
| User type | user / guest |
| Identity | User ID (authenticated) or remote IP (anonymous) |
| Path | /api/weatherforecast |
| Full key | rate_limit:user:42:/api/weatherforecast |
Service Registration
RedisRateLimiter is registered as a singleton by AddCustomRateLimiter:
RateLimiterExtensions for the full registration helper.
Direct Usage Example
WhileRedisRateLimiter is normally invoked automatically by RedisRateLimitingMiddleware,
you can also call it directly — for example inside a background service or a custom policy:
