style(backend): 清理幂等写入路径的注释
注释只保留一行级约束。 长段理由移入设计文档。 验证:go test -count=1 ./... 全绿。
This commit is contained in:
@@ -6,12 +6,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// CommentMQ 通过连接管理器发布评论事件(不再持有长生命周期 channel)。
|
||||
// CommentMQ 通过连接管理器发布评论事件。
|
||||
type CommentMQ struct {
|
||||
mgr *RabbitMQ
|
||||
}
|
||||
|
||||
// 拓扑常量导出:见 likeMQ.go 中的说明。
|
||||
const (
|
||||
CommentExchange = "comment.events"
|
||||
CommentQueue = "comment.events"
|
||||
@@ -40,9 +39,7 @@ func NewCommentMQ(base *RabbitMQ) (*CommentMQ, error) {
|
||||
return &CommentMQ{mgr: base}, nil
|
||||
}
|
||||
|
||||
// Publish 直接接收完整事件:event_id 由调用方(服务层)生成,因为它是
|
||||
// "这次用户意图"的标识,必须与兜底直写用的是同一个值(P0-4 §6.8)。
|
||||
// 只有 EventID 为空时才在这里补一个随机 id(老调用方/测试路径)。
|
||||
// Publish 接收完整事件;EventID 由调用方生成,仅为空时补一个随机值。
|
||||
func (c *CommentMQ) Publish(ctx context.Context, evt CommentEvent) error {
|
||||
return c.publish(ctx, "publish", CommentPublishRK, evt)
|
||||
}
|
||||
|
||||
@@ -27,14 +27,8 @@ func (c *Client) Del(ctx context.Context, key string) error {
|
||||
return c.rdb.Del(ctx, key).Err()
|
||||
}
|
||||
|
||||
// SetNX 仅在 key 不存在时写入,返回是否抢到了这个键。
|
||||
//
|
||||
// key 由调用方用 c.Key(...) 拼好(本方法不加前缀)——加前缀的时机必须
|
||||
// 和其他原语一致,否则同一个逻辑键会因为调用路径不同变成两个物理键。
|
||||
//
|
||||
// 失败(含 nil client)必须返回 error 而不是 (false, nil):调用方用它
|
||||
// 判断"这次意图是否已经生效过",把 Redis 故障静默说成"已生效"会导致
|
||||
// 该次加分被永久跳过。
|
||||
// SetNX 仅在 key 不存在时写入;key 由调用方拼好。
|
||||
// 失败必须返回 error,调用方据此判断占位是否生效。
|
||||
func (c *Client) SetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error) {
|
||||
if c == nil || c.rdb == nil {
|
||||
return false, errors.New("redis client not initialized")
|
||||
|
||||
Reference in New Issue
Block a user