refactor(p0-5): 收敛热度相关注释
背景叙述与历史取舍已写进 `docs/design/hot-ranking.md`,从源码删除。 只保留不变式与安全约束:`clientFoundRows` 禁令、唯一索引判重、 成员补零的排序约定、快照用 `RENAMENX` 只建一次、`EXPIRE` 失败即删键。 `video_service.go` 的 `NewVideoService` 注释原本复述已删方法的来历,一并收敛。 `zset.go` 的 `ZUnionStore` 与 `RenameNX` 注释各压到四行以内。 验证:go build ./... 通过。 验证:go vet ./... 通过。 验证:go test -count=1 ./... 全绿(本机无 cgo,未跑 -race)。 验证:go test -tags integration -p 1 -count=1 ./internal/feed/ ./internal/video/ ./internal/worker/ 全绿。
This commit is contained in:
@@ -49,12 +49,10 @@ func (c *Client) Expire(ctx context.Context, key string, ttl time.Duration) erro
|
||||
return c.rdb.Expire(ctx, key, ttl).Err()
|
||||
}
|
||||
|
||||
// ZUnionStore 计算 keys 指定的多个有序集合的并集,将结果存入 dst。
|
||||
// aggregate 控制分数聚合方式,可选 "SUM"、"MIN" 或 "MAX"。
|
||||
// ZUnionStore 计算 keys 的并集存入 dst,aggregate 可选 "SUM"/"MIN"/"MAX"。
|
||||
//
|
||||
// 返回并集的基数:调用方要靠它区分"真的空榜"与"并集为空但 dst 已被创建"。
|
||||
// ZUNIONSTORE 在没有成员时仍会写出一个空 key,若把它当成有效结果发布,
|
||||
// 这个 dst 就会被永久误认为"已经建好的快照"。
|
||||
// 返回基数:ZUNIONSTORE 在无成员时仍会写出空 key,调用方要靠它区分
|
||||
// "空结果"与"已写入的空集合"。
|
||||
func (c *Client) ZUnionStore(ctx context.Context, dst string, keys []string, aggregate string) (int64, error) {
|
||||
if c == nil || c.rdb == nil {
|
||||
return 0, nil
|
||||
@@ -67,9 +65,8 @@ func (c *Client) ZUnionStore(ctx context.Context, dst string, keys []string, agg
|
||||
|
||||
// RenameNX 仅在 dst 不存在时把 src 改名为 dst。
|
||||
//
|
||||
// 这是"快照只建一次"的关键动作:EXISTS + ZUNIONSTORE 是 check-then-act,
|
||||
// 两个并发请求都会判定"不存在",后到的那个覆盖先到的快照。RENAMENX 把
|
||||
// "占位"和"发布"合成一次原子操作,抢到的人发布,没抢到的人读赢家的。
|
||||
// 它是"快照只建一次"的关键:EXISTS + ZUNIONSTORE 是 check-then-act,
|
||||
// 并发请求会各自判定"不存在"并互相覆盖;RENAMENX 把占位与发布合成一次原子操作。
|
||||
func (c *Client) RenameNX(ctx context.Context, src, dst string) (bool, error) {
|
||||
if c == nil || c.rdb == nil {
|
||||
return false, errors.New("redis client not initialized")
|
||||
|
||||
Reference in New Issue
Block a user