.NET library designed to facilitate debounce and throttle mechanisms in distributed system environments, leveraging Redis for state management and distributed locking. This ensures that function executions are properly debounced or throttled across multiple instances, preventing excessive or unintended operations.
$ dotnet add package DistributedDebounceThrottleDistributedDebounceThrottle is a .NET library designed to facilitate debounce and throttle mechanisms in distributed system environments, leveraging Redis for state management and distributed locking. This ensures that function executions are properly debounced or throttled across multiple instances, preventing excessive or unintended operations.
Install DistributedDebounceThrottle via NuGet:
dotnet add package DistributedDebounceThrottle
To integrate DistributedDebounceThrottle in your application, ensure you have a Redis instance ready for connection. Here's how to get started:
In your application's startup configuration, register DistributedDebounceThrottle:
public void ConfigureServices(IServiceCollection services)
{
// Using an existing IConnectionMultiplexer instance:
services.AddDistributedDebounceThrottle(settings);
// Or, initiating a new IConnectionMultiplexer with a connection string:
services.AddDistributedDebounceThrottle(redisConnectionString, settings);
}
IDebounceThrottle:Inject IDebounceThrottle to access debounce and throttle dispatchers:
public class SampleService
{
private readonly IDispatcher _throttler;
public SampleService(IDebounceThrottle debounceThrottle)
{
_throttler = debounceThrottle.ThrottleDispatcher("uniqueDispatcherId", TimeSpan.FromSeconds(5));
}
public Task ExecuteThrottledOperation()
{
return _throttler.DispatchAsync(async () =>
{
// Operation logic here.
});
}
}
Customize your debounce and throttle settings via DebounceThrottleSettings:
RedisKeysPrefix: A prefix for all Redis keys (default "debounce-throttle:").RedLockExpiryTime: The expiry time for the distributed locks (default TimeSpan.FromSeconds(10)).Contributions are welcome! Feel free to fork the repository, submit pull requests, or report issues for bugs, features, or documentation improvements.
This project is licensed under the MIT License - see the LICENSE file in the repository for details.