package com.loadCenter.aliyun.gateway.cache; import com.loadCenter.aliyun.gateway.cache.abs.GatewayNodeCacheAbs; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; /** * @ClassName GatewayLoadSeriesCache * @Description 网关负载序列 * @Author ZeJinG.Su * @Date 19:47 2024/4/18 */ @Component public class GatewayLoadSeriesCache extends GatewayNodeCacheAbs { private final static String GATEWAY_LOAD_SERIES_KEY = "series"; @Override public String getPre() { return "gateway:load:"; } /** * bean创建完成之后执行方法 */ @PostConstruct public void init(){ redisService.setCacheObject(encode(GATEWAY_LOAD_SERIES_KEY),0); } /** * 获取当前序列值 * @return 序列值 */ public Long get(){ return redisService.getCacheObject(encode(GATEWAY_LOAD_SERIES_KEY)); } /** * 获取自增序列值 * @return 自增序列值 */ public Long incrementAndGet() { return redisService.increment(encode(GATEWAY_LOAD_SERIES_KEY),1L); } /** * 重置序列值 */ public void reset() { this.init(); } }