51 lines
1.2 KiB
Java
51 lines
1.2 KiB
Java
package com.loadCenter.aliyun.gateway.cache;
|
||
|
||
|
||
import com.loadCenter.aliyun.gateway.cache.abs.GatewayNodeCacheAbs;
|
||
import org.springframework.stereotype.Component;
|
||
|
||
import java.util.List;
|
||
|
||
/**
|
||
* @ClassName GatewayNodeCacheAbs
|
||
* @Description 网关节点缓存
|
||
* @Author ZeJinG.Su
|
||
* @Date 16:16 2024/4/18
|
||
*/
|
||
@Component
|
||
public class GatewayLoadNodeCache extends GatewayNodeCacheAbs {
|
||
|
||
private final static String GATEWAY_LOAD_NODE_KEY="node";
|
||
|
||
|
||
@Override
|
||
public String getPre() {
|
||
return "gateway:load:";
|
||
}
|
||
|
||
/**
|
||
* 存放负载集合
|
||
* @param nodeList 节点权重集合
|
||
*/
|
||
public void put(List<String> nodeList){
|
||
redisService.deleteObject(encode(GATEWAY_LOAD_NODE_KEY));
|
||
redisService.setCacheList(encode(GATEWAY_LOAD_NODE_KEY),nodeList);
|
||
}
|
||
|
||
/**
|
||
* 获取所有负载节点
|
||
* @return 负载节点集合
|
||
*/
|
||
public List<String> get() {
|
||
return redisService.getCacheList(encode(GATEWAY_LOAD_NODE_KEY));
|
||
}
|
||
|
||
|
||
public String getByIndex(Long index){
|
||
if(index == null || index >100){
|
||
throw new RuntimeException("下标违法,0-100");
|
||
}
|
||
return redisService.getCacheListValue(encode(GATEWAY_LOAD_NODE_KEY),index);
|
||
}
|
||
}
|