redis model update

pull/236/head
Gordon 2 years ago
parent 043188ab5e
commit d43b9fc6c1

@ -10,6 +10,7 @@ import (
"context"
"errors"
"fmt"
"github.com/golang/protobuf/jsonpb"
"github.com/garyburd/redigo/redis"
@ -33,22 +34,21 @@ func (d *DataBases) NewGetMessageListBySeq(userID string, seqList []uint32, oper
//MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1
key := messageCache + userID + "_" + strconv.Itoa(int(v))
result, err := d.rdb.HGetAll(context.Background(), key).Result()
result, err := d.rdb.Get(context.Background(), key).Result()
if err != nil {
errResult = err
failedSeqList = append(failedSeqList, v)
log2.NewWarn(operationID, "redis get message error:", err.Error(), v)
} else {
msg, err := Map2Pb(result)
//msg := pbCommon.MsgData{}
//err = jsonpb.UnmarshalString(result, &msg)
msg := pbCommon.MsgData{}
err = jsonpb.UnmarshalString(result, &msg)
if err != nil {
errResult = err
failedSeqList = append(failedSeqList, v)
log2.NewWarn(operationID, "Unmarshal err", result, err.Error())
} else {
log2.NewDebug(operationID, "redis get msg is ", msg.String())
seqMsg = append(seqMsg, msg)
seqMsg = append(seqMsg, &msg)
}
}
@ -69,21 +69,18 @@ func (d *DataBases) NewSetMessageToCache(msgList []*pbChat.MsgDataToMQ, uid stri
var failedList []pbChat.MsgDataToMQ
for _, msg := range msgList {
key := messageCache + uid + "_" + strconv.Itoa(int(msg.MsgData.Seq))
s, err := utils.Pb2Map(msg.MsgData)
s, err := utils.Pb2String(msg.MsgData)
if err != nil {
log2.NewWarn(operationID, utils.GetSelfFuncName(), "Pb2Map failed", msg.MsgData.String(), uid, err.Error())
log2.NewWarn(operationID, utils.GetSelfFuncName(), "Pb2String failed", msg.MsgData.String(), uid, err.Error())
continue
}
log2.NewDebug(operationID, "convert map is ", s)
fmt.Println("ts", s)
err = d.rdb.HMSet(context.Background(), key, s).Err()
log2.NewDebug(operationID, "convert string is ", s)
err = d.rdb.Set(ctx, key, s, time.Duration(config.Config.MsgCacheTimeout)*time.Second).Err()
//err = d.rdb.HMSet(context.Background(), "12", map[string]interface{}{"1": 2, "343": false}).Err()
if err != nil {
return err
log2.NewWarn(operationID, utils.GetSelfFuncName(), "redis failed", "args:", key, *msg, uid, s, err.Error())
failedList = append(failedList, *msg)
}
d.rdb.Expire(ctx, key, time.Second*time.Duration(config.Config.MsgCacheTimeout))
}
if len(failedList) != 0 {
return errors.New(fmt.Sprintf("set msg to cache failed, failed lists: %q,%s", failedList, operationID))

Loading…
Cancel
Save