diff --git a/internal/rpc/msg/rpcChat.go b/internal/rpc/msg/rpcChat.go index 00dc51161..1dee643c7 100644 --- a/internal/rpc/msg/rpcChat.go +++ b/internal/rpc/msg/rpcChat.go @@ -94,6 +94,7 @@ func (rpc *rpcChat) runCh() { if err := db.DB.DelMsgBySeqList(msg.UserID, msg.SeqList, msg.OperationID); err != nil { log.NewError(msg.OperationID, utils.GetSelfFuncName(), "DelMsgBySeqList qrgs: ", msg.UserID, msg.SeqList, msg.OperationID, err.Error()) } + db.DataBases.DelMsgFromCache(msg.SeqList, msg.UserID, msg.OperationID) } } } diff --git a/pkg/common/db/redisModel.go b/pkg/common/db/redisModel.go index 79ee58b5a..32ff05326 100644 --- a/pkg/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -313,3 +313,31 @@ func (d *DataBases) SetMessageToCache(msgList []*pbChat.MsgDataToMQ, uid string, } return nil } + +func (d *DataBases) DelMsgFromCache(seqList []uint32, uid, operationID string) { + for _, seq := range seqList { + key := messageCache + uid + "_" + strconv.Itoa(int(seq)) + result, err := redis.String(d.Exec("GET", key)) + if err != nil { + log2.NewWarn(operationID, utils.GetSelfFuncName(), "redis failed", "args:", key) + continue + } + log2.Debug(operationID, utils.GetSelfFuncName(), "del result", result) + var msg pbCommon.MsgData + err = utils.String2Pb(result, &msg) + if err != nil { + log2.NewWarn(operationID, utils.GetSelfFuncName(), "string2Pb failed", msg, err.Error()) + continue + } + msg.Status = 4 + s, err := utils.Pb2String(&msg) + if err != nil { + log2.NewWarn(operationID, utils.GetSelfFuncName(), "Pb2String failed", msg, err.Error()) + continue + } + _, err = d.Exec("SET", key, s, "ex", config.Config.MsgCacheTimeout) + if err != nil { + log2.NewWarn(operationID, utils.GetSelfFuncName(), "redis failed", "args:", key, msg, s) + } + } +} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 4c3e9e5f3..5346292ac 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -143,7 +143,10 @@ func Pb2String(pb proto.Message) (string, error) { EmitDefaults: false, } return marshaler.MarshalToString(pb) +} +func String2Pb(s string, pb proto.Message) error { + return proto.Unmarshal([]byte(s), pb) } func Map2Pb(m map[string]interface{}) (pb proto.Message, err error) {