package db import ( "Open_IM/pkg/common/config" log2 "Open_IM/pkg/common/log" pbChat "Open_IM/pkg/proto/chat" "Open_IM/pkg/utils" "context" "errors" "fmt" "strconv" "time" ) //func (d * DataBases)pubMessage(channel, msg string) { // d.rdb.Publish(context.Background(),channel,msg) //} //func (d * DataBases)pubMessage(channel, msg string) { // d.rdb.Publish(context.Background(),channel,msg) //} func (d *DataBases) NewSetMessageToCache(msgList []*pbChat.MsgDataToMQ, uid string, operationID string) error { ctx := context.Background() var failedList []pbChat.MsgDataToMQ for _, msg := range msgList { key := messageCache + uid + "_" + strconv.Itoa(int(msg.MsgData.Seq)) s, err := utils.Pb2Map(msg.MsgData) if err != nil { log2.NewWarn(operationID, utils.GetSelfFuncName(), "Pb2Map failed", msg.MsgData.String(), uid, err.Error()) continue } log2.NewDebug(operationID, "convert map is ", s) val, err := d.rdb.HMSet(ctx, key, s).Result() if err != nil { log2.NewWarn(operationID, utils.GetSelfFuncName(), "redis failed", "args:", key, *msg, uid, s, val) 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", failedList)) } return nil }