Class RedisRateLimiter

java.lang.Object
com.rale4j.sb.core.RedisRateLimiter
All Implemented Interfaces:
RateLimitStrategy

@Component("redis") public class RedisRateLimiter extends Object implements RateLimitStrategy
Rate limiter implementation using Redis.
  • Constructor Details

    • RedisRateLimiter

      public RedisRateLimiter(org.springframework.data.redis.core.RedisTemplate<String,String> redisTemplate)
      Constructor for RedisRateLimiter.
      Parameters:
      redisTemplate - the Redis template to be used for rate limiting
  • Method Details

    • allowRequest

      public boolean allowRequest(String key, int limit, int duration)
      Allows or denies a request based on the rate limit.
      Specified by:
      allowRequest in interface RateLimitStrategy
      Parameters:
      key - the key to identify the rate limit bucket
      limit - the maximum number of requests allowed
      duration - the duration in seconds for the rate limit
      Returns:
      true if the request is allowed, false otherwise