浏览代码

fix:更新redis

duxin 1 年之前
父节点
当前提交
71eb1fe50f
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      rpc/internal/common/messageService.go

+ 4 - 3
rpc/internal/common/messageService.go

@@ -64,8 +64,8 @@ func (service *MessageService) DeleteMessage(id []string, appId string) (int64,
 // 未读消息合计 isRedis 是否需要初始化redis
 func (service *MessageService) CountUnread(userId string, isRedis bool) (map[string]int64, int64) {
 	var (
-		count    int64
-		msgTypes []string
+		count              int64
+		msgTypes, groupIds []string
 	)
 	data := make(map[string]int64)
 	for _, v := range entity.MessageColumn {
@@ -73,6 +73,7 @@ func (service *MessageService) CountUnread(userId string, isRedis bool) (map[str
 			//去除全部与私信
 			msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, qutil.InterfaceToStr(v["group_id"])))
 			key := fmt.Sprintf(MsgCountKey, userId, util.IntAll(v["group_id"]))
+			groupIds = append(groupIds, qutil.InterfaceToStr(v["group_id"]))
 			if exists, _ := redis.Exists(redisModule, key); exists {
 				ct := util.Int64All(redis.GetInt(redisModule, key))
 				data[qutil.InterfaceToStr(v["group_id"])] = ct
@@ -91,7 +92,7 @@ func (service *MessageService) CountUnread(userId string, isRedis bool) (map[str
 			}
 		}
 		if isRedis { //初始化未读数
-			for _, v1 := range msgTypes {
+			for _, v1 := range groupIds {
 				key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v1))
 				redis.Put(redisModule, key, data[v1], -1)
 			}