Coder Social home page Coder Social logo

distributeddebouncethrottle's Introduction

DistributedDebounceThrottle

DistributedDebounceThrottle 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.

Features

  • Debounce: Ensures a function is executed only once after a specified interval since the last call, useful for minimizing redundant operations over a period.
  • Throttle: Limits the execution frequency of a function, ensuring it's not executed more than once within a specified timeframe.
  • Distributed Locks: Implements the RedLock algorithm for distributed locking to coordinate debounce and throttle logic across distributed systems.
  • Redis Integration: Utilizes Redis for managing timestamps and locks, offering a scalable solution for state synchronization.

Getting Started

Installation

Install DistributedDebounceThrottle via NuGet:

dotnet add package DistributedDebounceThrottle

Usage

To integrate DistributedDebounceThrottle in your application, ensure you have a Redis instance ready for connection. Here's how to get started:

1. Configure Services:

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);
}

2. Inject and Use 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.
        });
    }
}

Configuration

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)).

Contributing

Contributions are welcome! Feel free to fork the repository, submit pull requests, or report issues for bugs, features, or documentation improvements.

License

This project is licensed under the MIT License - see the LICENSE file in the repository for details.

distributeddebouncethrottle's People

Contributors

coddicat avatar

Stargazers

Carlos Alberto Costa Beppler avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.