samba/util/model/configClubRobot.go

43 lines
809 B
Go
Raw Permalink Normal View History

2025-06-04 09:51:39 +08:00
package model
import (
"context"
"encoding/json"
"github.com/go-redis/redis/v8"
"samba/pkg/log"
"samba/stub"
"strconv"
)
type ClubRobotConfigOp struct {
rdb *redis.Client
key string
}
func NewClubRobotConfigOp() *ClubRobotConfigOp {
return &ClubRobotConfigOp{rdb: rdbConfig, key: "robot|club"}
}
func (op *ClubRobotConfigOp) Load() {
table, err := op.rdb.HGetAll(context.Background(), op.key).Result()
if err != nil {
log.Error(err.Error())
return
}
id := int64(0)
for k, v := range table {
id, err = strconv.ParseInt(k, 10, 64)
if err != nil {
log.Error(err.Error())
continue
}
clubRobot := &stub.ClubRobotConfig{}
if err = json.Unmarshal([]byte(v), clubRobot); err != nil {
log.Error(err.Error())
continue
}
stub.ClubRobotConfigs[id] = clubRobot
}
return
}