All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.zhyd.braum.spring.boot.utils.GlobalBraumUtil Maven / Gradle / Ivy

The newest version!
package me.zhyd.braum.spring.boot.utils;

/**
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
 * @version 1.0
 * @since 1.8
 */
public enum GlobalBraumUtil {

    INSTANCE;

    private static final String PREFIX = "braum:black:";
    private static final String cacheKeyPrefix = "braum_";
    private static final String blacklistKeyPrefix = "braum_blacklist_";

    /**
     * @return  blog:black:braum_
     */
    public String getLockKey(String ip) {
        return PREFIX + formatKey(cacheKeyPrefix + ip);
    }

    /**
     * @return  blog:black:braum_blacklist_
     */
    public String getBlacklistKey(String ip) {
        return PREFIX + formatKey(blacklistKeyPrefix + ip);
    }

    public String formatKey(String key) {
        if (null == key || key.isEmpty()) {
            return null;
        }
        return key.replaceAll("[.:]", "_");
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy