Announcement

👇Official Account👇

Welcome to join the group & private message

Article first/tail QR code

Skip to content

Project 5: 统计模块

学习目标

  • 实现 PV/UV 统计
  • 用 ClickHouse 做数据洞察

统计方案

数据类型存储更新频率说明
PVRedis + MySQL实时INCR article:pv:{id}
UVRedis HyperLogLog实时PFADD article:uv:{id} {user_id}
阅读日志ClickHouse批量导入分析趋势、热门文章
用户行为Kafka → ClickHouse流式留存分析、转化率

Redis + HyperLogLog UV 统计

go
func RecordUV(ctx context.Context, articleID string, userID string) error {
    key := fmt.Sprintf("article:uv:%s", articleID)
    _, err := redis.PFAdd(ctx, key, userID).Result()
    return err
}

func GetUV(ctx context.Context, articleID string) (int64, error) {
    key := fmt.Sprintf("article:uv:%s", articleID)
    return redis.PFCount(ctx, key).Result()
}

上次更新于: