feat: 网元信息缓存redis
This commit is contained in:
@@ -28,7 +28,7 @@ type NeInfoImpl struct {
|
|||||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||||
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||||
var neInfo model.NeInfo
|
var neInfo model.NeInfo
|
||||||
key := fmt.Sprintf("%s%s.%s", cachekey.NE_KEY, neType, neID)
|
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, neType, neID)
|
||||||
jsonStr, _ := redis.Get("", key)
|
jsonStr, _ := redis.Get("", key)
|
||||||
if len(jsonStr) > 7 {
|
if len(jsonStr) > 7 {
|
||||||
err := json.Unmarshal([]byte(jsonStr), &neInfo)
|
err := json.Unmarshal([]byte(jsonStr), &neInfo)
|
||||||
@@ -49,7 +49,7 @@ func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeIn
|
|||||||
// RefreshByNeTypeAndNeID 通过ne_type和ne_id刷新redis中的缓存
|
// RefreshByNeTypeAndNeID 通过ne_type和ne_id刷新redis中的缓存
|
||||||
func (r *NeInfoImpl) RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
func (r *NeInfoImpl) RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||||
var neInfo model.NeInfo
|
var neInfo model.NeInfo
|
||||||
key := fmt.Sprintf("%s%s.%s", cachekey.NE_KEY, neType, neID)
|
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, neType, neID)
|
||||||
redis.Del("", key)
|
redis.Del("", key)
|
||||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||||
if neInfo.NeId == neID {
|
if neInfo.NeId == neID {
|
||||||
@@ -188,7 +188,13 @@ func (r *NeInfoImpl) Insert(neInfo model.NeInfo) string {
|
|||||||
}
|
}
|
||||||
neInfo.HostIDs = strings.Join(hostIDs, ",")
|
neInfo.HostIDs = strings.Join(hostIDs, ",")
|
||||||
}
|
}
|
||||||
return r.neInfoRepository.Insert(neInfo)
|
|
||||||
|
insertId := r.neInfoRepository.Insert(neInfo)
|
||||||
|
if insertId != "" {
|
||||||
|
// 刷新缓存
|
||||||
|
r.RefreshByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||||
|
}
|
||||||
|
return insertId
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update 修改信息
|
// Update 修改信息
|
||||||
@@ -203,7 +209,13 @@ func (r *NeInfoImpl) Update(neInfo model.NeInfo) int64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r.neInfoRepository.Update(neInfo)
|
|
||||||
|
num := r.neInfoRepository.Update(neInfo)
|
||||||
|
if num > 0 {
|
||||||
|
// 刷新缓存
|
||||||
|
r.RefreshByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||||
|
}
|
||||||
|
return num
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteByIds 批量删除信息
|
// DeleteByIds 批量删除信息
|
||||||
@@ -215,12 +227,15 @@ func (r *NeInfoImpl) DeleteByIds(infoIds []string) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(infos) == len(infoIds) {
|
if len(infos) == len(infoIds) {
|
||||||
// 主机信息删除
|
|
||||||
for _, v := range infos {
|
for _, v := range infos {
|
||||||
|
// 主机信息删除
|
||||||
if v.HostIDs != "" {
|
if v.HostIDs != "" {
|
||||||
hostIds := strings.Split(v.HostIDs, ",")
|
hostIds := strings.Split(v.HostIDs, ",")
|
||||||
r.neHostRepository.DeleteByIds(hostIds)
|
r.neHostRepository.DeleteByIds(hostIds)
|
||||||
}
|
}
|
||||||
|
// 缓存信息删除
|
||||||
|
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, v.NeType, v.NeId)
|
||||||
|
redis.Del("", key)
|
||||||
}
|
}
|
||||||
rows := r.neInfoRepository.DeleteByIds(infoIds)
|
rows := r.neInfoRepository.DeleteByIds(infoIds)
|
||||||
return rows, nil
|
return rows, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user