业务要求
流量:超高流量、亿级数据
分页查询:排序:按热度,展示前N条数据,每条评论第一次展开3条,再点击展开10条



缓存设计
读缓存:
1、redis查询前10条评论
2、pipelined一次查询,出10条评论的详情信息
3、用户点击每个评论进行展开时,调用子评论zset获取评论列表,再pipelined一次查询子评论的详情数据
注意:
子评论只需要记录父级评论(回复了谁)
zset存储1000条数据,不进行全量保持。
评论详情数据,静态数据用string保存,动态数据(如:点赞数、评论数等)用hash保存
1、前N条评论:zset
comment_vid_{video_id1} :[{comment_id1:score1},{comment_id2:score2},....]
2、评论的子评论:zset
commit_reply_{comment_id1} :[{reply_id1:score1},{reply_id2:score2},....]
3、评论详情(评论、子评论): string和hash
//评论
comment_detail_{commit_id1}:
{
"user_id":"",
"content":"真是太有意思了",
"likeCount":"120",
"replyCount":"192",
"create_time":"1719888000000",
"video_id":"", //后续用于展示我的评论列表
"top_2_replies": [
{"reply_id1": 901, "user_id": "", "text": "确实,看到一半我跪了"},
{"reply_id2": 902, "user_id": "", "text": "三连走起"}
]
}
//子评论
comment_reply_detail_{replay_id2}:
{
"user_id":"",
"content":"你说的太有意思了",
"parentId":"commit_id1",
"to_user_id":"",
"likeCount":"120",
"replyCount":"192",
"create_time":"1719888000000",
"video_id":"" //后续用于展示我的评论列表
}
数据库设计
CREATE TABLE `comment`(
`id` bigint(20) unsigned NOT NULL COMMENT '评论ID(雪花算法生成)',
`biz_id` bigint(20) NOT NULL COMMENT '业务ID(如微博ID)',
`biz_type` tinyint(4) NOT NULL DEFAULT 1 COMMENT '业务类型(1=微博,2=视频,3=文章)',
`user_id` bigint(20) NOT NULL COMMENT '评论用户ID',
`content` varchar(1000) NOT NULL COMMENT '评论内容(过滤敏感词后)',
`parent_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '父评论ID(0=一级评论,>0=回复)',
`root_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '根评论ID(所有层级回复共享根评论ID)',
`like_count` int(11) NOT NULL DEFAULT 0 COMMENT '点赞数',
`reply_count` int(11) NOT NULL DEFAULT 0 COMMENT '评论数',
`status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态(1=正常,0=删除,2=审核中)',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `idx_biz_root` (`biz_type`,`biz_id`,`root_id`,`status`,`create_time`),
KEY `idx_root_parent` (`root_id`,`parent_id`,`status`,`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '评论表(含回复,统一存储)';
内容安全
- 评论提交时,同步调用内容审核接口(如阿里云绿网、腾讯云内容安全),违规内容(如色情、辱骂)直接拦截,返回 “评论包含敏感信息”;
- 审核不通过的内容存入 “违规评论表”,后续人工复核,避免流入数据库;
引用:
微博:https://cloud.tencent.com/developer/article/2583950
B站:https://www.bilibili.com/read/cv20346888/?opus_fallback=1

972

被折叠的 条评论
为什么被折叠?



