style(backend): 精简 P1-1 期间的说明性注释

代码只留一行不变量。进程分工的动机、退避与重连的细节、测试可验证性的理由,都已在 docs/solutions/P1-1-async-workers-out-of-api.md 里写过,注释不再复述。

保留的是读代码看不出来的约束:超时派生自 poller 的 ctx、坏消息不能打断订阅、SSE 响应永不结束、订阅存活够久要重置退避。

文档补一句退避重置规则。这是删掉的注释里唯一没有落在文档上的细节。

验证:go test -count=1 ./... 全绿。
This commit is contained in:
2026-11-08 15:47:10 +08:00
parent 06e001a151
commit 5d05c147ed
10 changed files with 26 additions and 67 deletions

View File

@@ -103,8 +103,7 @@ func (c *Client) Unlock(ctx context.Context, key string, token string) error {
return err
}
// Publish 向频道发布一条消息。频道名由调用方用 Key 统一加前缀,
// 同一 Redis 上的多套环境才不会互相收到对方的消息。
// 频道名由调用方用 Key 加前缀,多环境共享同一 Redis 时不串台。
func (c *Client) Publish(ctx context.Context, channel string, payload []byte) error {
if c == nil || c.rdb == nil {
return errors.New("redis client not initialized")
@@ -112,9 +111,7 @@ func (c *Client) Publish(ctx context.Context, channel string, payload []byte) er
return c.rdb.Publish(ctx, channel, payload).Err()
}
// Subscribe 订阅频道,并在返回前等到 broker 确认订阅生效:
// 否则"订阅建立"与"第一条消息到达"之间有一个静默丢消息的窗口。
// 返回的 PubSub 由调用方负责 Close。
// Subscribe 返回前等 broker 确认订阅生效,避免丢第一批消息;PubSub 由调用方 Close。
func (c *Client) Subscribe(ctx context.Context, channel string) (*redis.PubSub, error) {
if c == nil || c.rdb == nil {
return nil, errors.New("redis client not initialized")