Browse Source

update 不合理的数据提前处理

dev
lucas 3 months ago
parent
commit
d7bc6e64f1
  1. 26
      configHelper.go

26
configHelper.go

@ -177,16 +177,21 @@ func (the *ConfigHelper) GetDeviceStationIds(deviceId string) ([]int, error) {
}
func (the *ConfigHelper) SetChainedCacheObj(k string, obj any) error {
var value string
if v, ok := obj.(string); !ok {
v, err := json.Marshal(obj)
var err error
switch obj.(type) {
case string:
value = obj.(string)
case []byte:
value = string(obj.([]byte))
default:
bs, err := json.Marshal(obj)
if err != nil {
return err
}
value = string(v)
} else {
value = v
value = string(bs)
}
err := the.chainedCache.LoadableChinCache.Set(the.ctx, k, value)
err = the.chainedCache.LoadableChinCache.Set(the.ctx, k, value)
return err
}
func (the *ConfigHelper) SetChainedCacheObjWithExpiration(k string, obj any, duration time.Duration) error {
@ -253,7 +258,11 @@ func (the *ConfigHelper) SetDeviceStationObjs(deviceId string, stations common_m
var err error
k := fmt.Sprintf("%s:%s", redisKey.Device_stationObjs, deviceId)
err = the.SetChainedCacheObj(k, &stations)
bytes, err := json.Marshal(stations)
if err != nil {
return err
}
go the.SetChainedCacheObj(k, bytes)
return err
}
@ -389,6 +398,9 @@ func (the *ConfigHelper) GetStationGroup(groupId int) (common_models.StationGrou
k := fmt.Sprintf("%s:%d", redisKey.Group, groupId)
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k)
if v, ok := value.(string); ok {
if v == "" {
return group, err
}
err = json.Unmarshal([]byte(v), &group)
if err != nil {
log.Printf("json unmarshal error:%s \n", err.Error())

Loading…
Cancel
Save