refactor(models): remove mergo dependency and update SetRedisFileInfo and SetRedisShareInfo to use handler functions for improved data handling

This commit is contained in:
keven1024
2026-04-06 11:15:02 +08:00
parent d3e7760aea
commit 55949d1f76
4 changed files with 14 additions and 14 deletions

View File

@@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"pkg/utils" "pkg/utils"
"dario.cat/mergo"
"github.com/redis/rueidis" "github.com/redis/rueidis"
) )
@@ -45,15 +44,16 @@ func GetRedisFileInfo(fileId string) (*RedisFileInfo, error) {
return &fileInfoData, nil return &fileInfoData, nil
} }
func SetRedisFileInfo(fileId string, fileInfo RedisFileInfo) error { func SetRedisFileInfo(fileId string, handler func(fileInfo *RedisFileInfo) *RedisFileInfo) error {
rdb, ctx := utils.GetRedisClient() rdb, ctx := utils.GetRedisClient()
old_fileInfo, err := GetRedisFileInfo(fileId) old_fileInfo, err := GetRedisFileInfo(fileId)
if err != nil { if err != nil {
return err return err
} }
if old_fileInfo != nil { if old_fileInfo == nil {
mergo.Merge(&fileInfo, old_fileInfo) old_fileInfo = &RedisFileInfo{}
} }
fileInfo := handler(old_fileInfo)
jsonData, _ := json.Marshal(fileInfo) jsonData, _ := json.Marshal(fileInfo)
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()
} }

View File

@@ -2,10 +2,7 @@ module pkg/models
go 1.25.5 go 1.25.5
require ( require github.com/redis/rueidis v1.0.73
dario.cat/mergo v1.0.2
github.com/redis/rueidis v1.0.73
)
require ( require (
golang.org/x/net v0.52.0 // indirect golang.org/x/net v0.52.0 // indirect

View File

@@ -1,11 +1,14 @@
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/onsi/gomega v1.38.3 h1:eTX+W6dobAYfFeGC2PV6RwXRu/MyT+cQguijutvkpSM= github.com/onsi/gomega v1.38.3 h1:eTX+W6dobAYfFeGC2PV6RwXRu/MyT+cQguijutvkpSM=
github.com/onsi/gomega v1.38.3/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4=
github.com/redis/rueidis v1.0.73 h1:0Enrg0VuMdaYyNDDj0lLIheWY0uybCeQOh+jTp2GG3M= github.com/redis/rueidis v1.0.73 h1:0Enrg0VuMdaYyNDDj0lLIheWY0uybCeQOh+jTp2GG3M=
github.com/redis/rueidis v1.0.73/go.mod h1:lfdcZzJ1oKGKL37vh9fO3ymwt+0TdjkkUCJxbgpmcgQ= github.com/redis/rueidis v1.0.73/go.mod h1:lfdcZzJ1oKGKL37vh9fO3ymwt+0TdjkkUCJxbgpmcgQ=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=

View File

@@ -7,7 +7,6 @@ import (
"pkg/utils" "pkg/utils"
"dario.cat/mergo"
"github.com/redis/rueidis" "github.com/redis/rueidis"
) )
@@ -52,15 +51,16 @@ func GetRedisShareInfo(shareId string) (*RedisShareInfo, error) {
return &shareInfoData, nil return &shareInfoData, nil
} }
func SetRedisShareInfo(shareId string, shareInfo RedisShareInfo) error { func SetRedisShareInfo(shareId string, handler func(shareInfo *RedisShareInfo) *RedisShareInfo) error {
rdb, ctx := utils.GetRedisClient() rdb, ctx := utils.GetRedisClient()
old_shareInfo, err := GetRedisShareInfo(shareId) old_shareInfo, err := GetRedisShareInfo(shareId)
if err != nil { if err != nil {
return err return err
} }
if old_shareInfo != nil { if old_shareInfo == nil {
mergo.Merge(&shareInfo, old_shareInfo) old_shareInfo = &RedisShareInfo{}
} }
shareInfo := handler(old_shareInfo)
jsonData, _ := json.Marshal(shareInfo) jsonData, _ := json.Marshal(shareInfo)
return rdb.Do( return rdb.Do(
ctx, ctx,