suzejing/src/main/java/com/loadCenter/aliyun/gateway/cache/GatewayLoadNodeCache.java

51 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}