Browse Source

update 不合理的数据提前处理

dev
lucas 1 month 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 { func (the *ConfigHelper) SetChainedCacheObj(k string, obj any) error {
var value string var value string
if v, ok := obj.(string); !ok { var err error
v, err := json.Marshal(obj) switch obj.(type) {
case string:
value = obj.(string)
case []byte:
value = string(obj.([]byte))
default:
bs, err := json.Marshal(obj)
if err != nil { if err != nil {
return err return err
} }
value = string(v) value = string(bs)
} else {
value = v
} }
err := the.chainedCache.LoadableChinCache.Set(the.ctx, k, value)
err = the.chainedCache.LoadableChinCache.Set(the.ctx, k, value)
return err return err
} }
func (the *ConfigHelper) SetChainedCacheObjWithExpiration(k string, obj any, duration time.Duration) error { 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 var err error
k := fmt.Sprintf("%s:%s", redisKey.Device_stationObjs, deviceId) 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 return err
} }
@ -389,6 +398,9 @@ func (the *ConfigHelper) GetStationGroup(groupId int) (common_models.StationGrou
k := fmt.Sprintf("%s:%d", redisKey.Group, groupId) k := fmt.Sprintf("%s:%d", redisKey.Group, groupId)
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k)
if v, ok := value.(string); ok { if v, ok := value.(string); ok {
if v == "" {
return group, err
}
err = json.Unmarshal([]byte(v), &group) err = json.Unmarshal([]byte(v), &group)
if err != nil { if err != nil {
log.Printf("json unmarshal error:%s \n", err.Error()) log.Printf("json unmarshal error:%s \n", err.Error())

Loading…
Cancel
Save