45 lines
1.1 KiB
Java
45 lines
1.1 KiB
Java
package com.yao.gateWay.cache;
|
|
|
|
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
/**
|
|
* @Author: LiJiaYao
|
|
* @Date: 2024/4/18
|
|
* @Description: 网关节点缓存
|
|
*/
|
|
@Component
|
|
public class GatewayNodeCache extends GatewayNodeAbstract {
|
|
|
|
private final static String nodePre= "gateway:node:info:";
|
|
public String encode (String nodeId){
|
|
return nodePre+nodeId;
|
|
}
|
|
|
|
/**
|
|
* 增加缓存信息
|
|
* @param gateWayNodeInfo 节点信息
|
|
*/
|
|
public void add(GateWayNodeInfo gateWayNodeInfo){
|
|
redisService.setCacheObject(encode(gateWayNodeInfo.getNodeId()),gateWayNodeInfo);
|
|
}
|
|
|
|
/**
|
|
* 获取节点信息
|
|
* @param nodeId 缓存名称
|
|
* @return GateWayNodeInfo 节点信息
|
|
*/
|
|
public GateWayNodeInfo get(String nodeId){
|
|
return redisService.getCacheObject(encode(nodeId));
|
|
}
|
|
|
|
/**
|
|
* 删除节点信息
|
|
* @param nodeId 节点id
|
|
*/
|
|
public void remove(String nodeId){
|
|
redisService.deleteObject(encode(nodeId));
|
|
}
|
|
|
|
}
|