51 lines
1.0 KiB
Java
51 lines
1.0 KiB
Java
package com.yao.gateway.cache;
|
|
|
|
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
/**
|
|
* @Author: LiJiaYao
|
|
* @Date: 2024/4/18
|
|
* @Description: 网关负载序列
|
|
*/
|
|
@Component
|
|
public class GatewayLoadSeriesCache extends GatewayNodeAbstract {
|
|
|
|
public static final String gatewayLoadSeriesKey = "gateway:load:series";
|
|
|
|
/**
|
|
* 初始化
|
|
* bean创建完成之后执行方法
|
|
*/
|
|
@PostConstruct
|
|
public void init(){
|
|
redisService.setCacheObject(gatewayLoadSeriesKey,0L);
|
|
}
|
|
|
|
/**
|
|
* 获取当前序列值
|
|
* @return 序列值
|
|
*/
|
|
public Long get(){
|
|
return redisService.getCacheObject(gatewayLoadSeriesKey);
|
|
}
|
|
|
|
/**
|
|
* 获取自增序列值
|
|
* @return 自增后的值
|
|
*/
|
|
public Long incrementAndGet(){
|
|
return redisService.increment(gatewayLoadSeriesKey,1L);
|
|
}
|
|
|
|
/**
|
|
* 重置 刷新
|
|
*/
|
|
public void refresh(){
|
|
this.init();
|
|
}
|
|
|
|
}
|