1 package org.oxerr.rescu.ext.ratelimiter.redisson;
2
3 import org.oxerr.rescu.ext.ratelimiter.RateLimiter;
4 import org.redisson.api.RRateLimiter;
5 import org.redisson.api.RateIntervalUnit;
6 import org.redisson.api.RateType;
7 import org.redisson.api.RedissonClient;
8
9 public class RedissonRateLimiter implements RateLimiter {
10
11 private final RRateLimiter rateLimiter;
12
13 public RedissonRateLimiter(RRateLimiter rateLimiter) {
14 this.rateLimiter = rateLimiter;
15 }
16
17 public RedissonRateLimiter(RedissonClient redisson, String name) {
18 this.rateLimiter = redisson.getRateLimiter(name);
19 }
20
21
22
23
24
25
26
27
28
29 public void setRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit) {
30 this.rateLimiter.setRate(mode, rate, rateInterval, rateIntervalUnit);
31 }
32
33 @Override
34 public void acquire() {
35 this.rateLimiter.acquire();
36 }
37
38 public RRateLimiter getRateLimiter() {
39 return this.rateLimiter;
40 }
41
42 }