Cannot make the RateLimit.Redis 4.0.1 work
See original GitHub issueI’m trying to implement the Ratelimit with redis but I keep receiving a lot of errors that I couldn’t handle yet, so I’m begging for help.
My extesion method that implements all the rateLimit configuration:
public static IServiceCollection ConfigureRateLimit(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
//load general configuration from appsettings.json
services.Configure<IpRateLimitOptions>(configuration.GetSection("IpRateLimiting"));
services.AddStackExchangeRedisCache(options =>
{
options.ConfigurationOptions = new ConfigurationOptions
{
//silently retry in the background if the Redis connection is temporarily down
AbortOnConnectFail = false
};
options.Configuration = configuration.GetConnectionString("Redis");
options.InstanceName = "HubRateLimit";
});
var redisOptions = ConfigurationOptions.Parse(configuration["ConnectionStrings:Redis"]);
services.AddSingleton<IConnectionMultiplexer>(provider => ConnectionMultiplexer.Connect(redisOptions););
services.AddRedisRateLimiting();
// configuration (resolvers, counter key builders)
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
return services;
}
The following block was added since I was receiving the IDistributedCache error, since I added this block this error doesn’t occur anymore
services.AddStackExchangeRedisCache(options =>
{
options.ConfigurationOptions = new ConfigurationOptions
{
//silently retry in the background if the Redis connection is temporarily down
AbortOnConnectFail = false
};
options.Configuration = configuration.GetConnectionString("Redis");
options.InstanceName = "HubRateLimit";
});
But I still have issues, since I get the following error when I try to call ANY endpoint:
My appsettings configuration is set as the following JSON:
"IpRateLimiting": {
"EnableEndpointRateLimiting": false,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"GeneralRules": [
{
"Endpoint": "*:/api/*",
"Period": "1s",
"Limit": 2
}
]
}
Am I doing something wrong ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
How to see keys set by django-ratelimit in redis server?
I am trying to set up a rate-limit to limit the number of times a POST request is called. I have this in...
Read more >Rate Limiting is not working in Istio 1.9 - Networking
It shows 500 response code for all the requests. But local rate limiting seems to be working fine. This is the redis config...
Read more >p-ratelimit
This is an easy-to-use utility for calling rate-limited APIs. It will prevent you from exceeding rate limits by queueing requests that would ...
Read more >rate-limit-redis
Start using rate-limit-redis in your project by running `npm i ... Create and use the rate limiter const limiter = rateLimit({ // Rate ......
Read more >Rate Limiting - What is Rate Limiting? | Redis
In web applications, rate limiting restricts the number of requests that a client can make to a server within a given time period...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@luccasmf Hello, I also encountered the same problem. No more errors after using the following method.
Try adding the following at the end of extension method
I got it working with above configuration.