From c32b53b3c00bd372ba30df8f852ead31f5bf162e Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 24 May 2022 17:22:17 +0800 Subject: [PATCH] msg cache --- config/config.yaml | 2 ++ pkg/common/config/config.go | 1 + pkg/common/db/redisModel.go | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 643ee88a4..552290e6b 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -227,6 +227,8 @@ multiloginpolicy: 1 chatpersistencemysql: true #可靠性存储 reliablestorage: false +#消息缓存时间 +msgCacheTimeout: 60 * 60 #token config tokenpolicy: diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 290e63ec2..76e80767e 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -218,6 +218,7 @@ type config struct { MultiLoginPolicy int `yaml:"multiloginpolicy"` ChatPersistenceMysql bool `yaml:"chatpersistencemysql"` ReliableStorage bool `yaml:"reliablestorage"` + MsgCacheTimeout int `yaml:"msgCacheTimeout"` TokenPolicy struct { AccessSecret string `yaml:"accessSecret"` diff --git a/pkg/common/db/redisModel.go b/pkg/common/db/redisModel.go index 2e1363b4d..41c7ea6c1 100644 --- a/pkg/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -1,6 +1,7 @@ package db import ( + "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" log2 "Open_IM/pkg/common/log" pbChat "Open_IM/pkg/proto/chat" @@ -274,7 +275,7 @@ func (d *DataBases) SetMessageToCache(msgList []*pbChat.MsgDataToMQ, uid string) continue } log2.NewDebug("", "m", m) - _, err = d.Exec("hmset", key, redis.Args{}.Add().AddFlat(m)...) + _, err = d.Exec("hmset", key, redis.Args{}.Add("TIMEOUT", config.Config.MsgCacheTimeout).AddFlat(m)...) if err != nil { log2.NewWarn("", utils.GetSelfFuncName(), "redis failed", "args:", key, *msg, uid, m) failedList = append(failedList, *msg)