com.founder.core.ratelimiter.TimeWindowRateLimiter Maven / Gradle / Ivy
package com.founder.core.ratelimiter;
import com.founder.core.model.LuaScript;
import com.founder.core.model.Result;
import com.founder.core.model.Rule;
import org.redisson.api.RScript;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.LongCodec;
import org.springframework.beans.factory.annotation.Qualifier;
import java.util.Collections;
import java.util.List;
import static com.founder.core.starter.RateLimiterAutoConfiguration.REDISSON_BEAN_NAME;
public class TimeWindowRateLimiter implements RateLimiter {
private final RScript rScript;
public TimeWindowRateLimiter(@Qualifier(REDISSON_BEAN_NAME) RedissonClient client) {
this.rScript = client.getScript(LongCodec.INSTANCE);
}
@Override
public Result isAllowed(Rule rule) {
List