luoyb
2021-06-03 ae8267320996082be9bae84aa5248ca76d735777
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package cc.mrbird.febs.gateway.enhance.utils;
 
 
import cc.mrbird.febs.common.core.entity.constant.FebsConstant;
 
/**
 * @author MrBird
 */
public abstract class RouteEnhanceCacheUtil {
 
    private static final String BLACKLIST_CHACHE_KEY_PREFIX = "febs:route:blacklist:";
    private static final String RATELIMIT_CACHE_KEY_PREFIX = "febs:route:ratelimit:";
    private static final String RATELIMIT_COUNT_KEY_PREFIX = "febs:route:ratelimit:cout:";
 
    public static String getBlackListCacheKey(String ip) {
        if (FebsConstant.LOCALHOST.equalsIgnoreCase(ip)) {
            ip = FebsConstant.LOCALHOST_IP;
        }
        return String.format("%s%s", BLACKLIST_CHACHE_KEY_PREFIX, ip);
    }
 
    public static String getBlackListCacheKey() {
        return String.format("%sall", BLACKLIST_CHACHE_KEY_PREFIX);
    }
 
    public static String getRateLimitCacheKey(String uri, String method) {
        return String.format("%s%s:%s", RATELIMIT_CACHE_KEY_PREFIX, uri, method);
    }
 
    public static String getRateLimitCountKey(String uri, String ip) {
        return String.format("%s%s:%s", RATELIMIT_COUNT_KEY_PREFIX, uri, ip);
    }
}