Class RedisBasedRateLimiter

java.lang.Object
io.github.devlibx.easy.ratelimit.redis.RedisBasedRateLimiter
All Implemented Interfaces:
IRateLimiter

public class RedisBasedRateLimiter extends Object implements IRateLimiter
  • Constructor Details

  • Method Details

    • start

      public void start()
      Description copied from interface: IRateLimiter
      Start rate limiter
      Specified by:
      start in interface IRateLimiter
    • trySetRate

      public boolean trySetRate(long rate)
      Description copied from interface: IRateLimiter
      Initializes RateLimiter's state and stores config to Redis server. Params: mode – - rate mode rate – - rate rateInterval – - rate time interval rateIntervalUnit – - rate time interval unit Returns: true if rate was set and false otherwise
      Specified by:
      trySetRate in interface IRateLimiter
    • acquire

      public void acquire()
      Description copied from interface: IRateLimiter
      Acquires a permit from this RateLimiter, blocking until one is available. Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
      Specified by:
      acquire in interface IRateLimiter
    • acquire

      public void acquire(long permits)
      Description copied from interface: IRateLimiter
      Acquires a specified permits from this RateLimiter, blocking until one is available.

      Acquires the given number of permits, if they are available and returns immediately, reducing the number of available permits by the given amount.

      Specified by:
      acquire in interface IRateLimiter
      Parameters:
      permits - the number of permits to acquire
    • stop

      public void stop()
      Description copied from interface: IRateLimiter
      Stop rate limiter
      Specified by:
      stop in interface IRateLimiter
    • debug

      public StringObjectMap debug()
      Specified by:
      debug in interface IRateLimiter
      Returns:
      debug info