mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
fix(models): handle JSON marshaling errors in SetRedis functions to improve error handling and data integrity
This commit is contained in:
@@ -54,7 +54,10 @@ func SetRedisFileInfo(fileId string, handler func(fileInfo *RedisFileInfo) *Redi
|
|||||||
old_fileInfo = &RedisFileInfo{}
|
old_fileInfo = &RedisFileInfo{}
|
||||||
}
|
}
|
||||||
fileInfo := handler(old_fileInfo)
|
fileInfo := handler(old_fileInfo)
|
||||||
jsonData, _ := json.Marshal(fileInfo)
|
jsonData, err := json.Marshal(fileInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return rdb.Do(ctx, rdb.B().Hset().Key("015:fileInfoMap").FieldValue().FieldValue(fileId, string(jsonData)).Build()).Error()
|
return rdb.Do(ctx, rdb.B().Hset().Key("015:fileInfoMap").FieldValue().FieldValue(fileId, string(jsonData)).Build()).Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ func GetRedisFileShareRelational(fileId string) ([]string, error) {
|
|||||||
|
|
||||||
func SetRedisFileShareRelational(fileId string, shareIDs []string) error {
|
func SetRedisFileShareRelational(fileId string, shareIDs []string) error {
|
||||||
rdb, ctx := utils.GetRedisClient()
|
rdb, ctx := utils.GetRedisClient()
|
||||||
jsonData, _ := json.Marshal(shareIDs)
|
jsonData, err := json.Marshal(shareIDs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return rdb.Do(ctx, rdb.B().Hset().Key("015:fileShareRelational").FieldValue().FieldValue(fileId, string(jsonData)).Build()).Error()
|
return rdb.Do(ctx, rdb.B().Hset().Key("015:fileShareRelational").FieldValue().FieldValue(fileId, string(jsonData)).Build()).Error()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ func SetRedisShareInfo(shareId string, handler func(shareInfo *RedisShareInfo) *
|
|||||||
old_shareInfo = &RedisShareInfo{}
|
old_shareInfo = &RedisShareInfo{}
|
||||||
}
|
}
|
||||||
shareInfo := handler(old_shareInfo)
|
shareInfo := handler(old_shareInfo)
|
||||||
jsonData, _ := json.Marshal(shareInfo)
|
jsonData, err := json.Marshal(shareInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return rdb.Do(
|
return rdb.Do(
|
||||||
ctx,
|
ctx,
|
||||||
rdb.B().Set().
|
rdb.B().Set().
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ func SetRedisStat(key string, handler func(stat *StatData) *StatData) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stat := handler(old_stat)
|
stat := handler(old_stat)
|
||||||
jsonData, _ := json.Marshal(stat)
|
jsonData, err := json.Marshal(stat)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return rdb.Do(ctx, rdb.B().Hset().Key("015:stat").FieldValue().FieldValue(key, string(jsonData)).Build()).Error()
|
return rdb.Do(ctx, rdb.B().Hset().Key("015:stat").FieldValue().FieldValue(key, string(jsonData)).Build()).Error()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,10 @@ func GetRedisTaskInfo(taskId string) (*map[string]any, error) {
|
|||||||
|
|
||||||
func SetRedisTaskInfo(taskId string, taskInfo map[string]any) error {
|
func SetRedisTaskInfo(taskId string, taskInfo map[string]any) error {
|
||||||
rdb, ctx := utils.GetRedisClient()
|
rdb, ctx := utils.GetRedisClient()
|
||||||
jsonData, _ := json.Marshal(taskInfo)
|
jsonData, err := json.Marshal(taskInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return rdb.Do(
|
return rdb.Do(
|
||||||
ctx,
|
ctx,
|
||||||
rdb.B().Set().Key(fmt.Sprintf("015:taskInfoMap:%s", taskId)).Value(string(jsonData)).Ex(time.Hour).Build(),
|
rdb.B().Set().Key(fmt.Sprintf("015:taskInfoMap:%s", taskId)).Value(string(jsonData)).Ex(time.Hour).Build(),
|
||||||
|
|||||||
Reference in New Issue
Block a user