add 增加 获取redis客户端实例id工具
This commit is contained in:
parent
089b3d6e6d
commit
30fe14c0ff
@ -29,14 +29,26 @@ public class RedisUtils {
|
||||
* 限流
|
||||
*
|
||||
* @param key 限流key
|
||||
* @param limitType 限流类型
|
||||
* @param rateType 限流类型
|
||||
* @param rate 速率
|
||||
* @param rateInterval 速率间隔
|
||||
* @return -1 表示失败
|
||||
*/
|
||||
public static boolean rateLimiter(String key, RateType rateType, int rate, int rateInterval) {
|
||||
public static long rateLimiter(String key, RateType rateType, int rate, int rateInterval) {
|
||||
RRateLimiter rateLimiter = client.getRateLimiter(key);
|
||||
rateLimiter.trySetRate(rateType, rate, rateInterval, RateIntervalUnit.SECONDS);
|
||||
return rateLimiter.tryAcquire();
|
||||
if (rateLimiter.tryAcquire()) {
|
||||
return rateLimiter.availablePermits();
|
||||
} else {
|
||||
return -1L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实例id
|
||||
*/
|
||||
public static String getClientId() {
|
||||
return client.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user