This commit is contained in:
eafonyang
2026-06-05 20:15:30 +08:00
parent 8c22be4e0a
commit 99785672a5
15 changed files with 439 additions and 8 deletions
+22 -4
View File
@@ -80,14 +80,32 @@ func (t *DevicePersistTask) Persist() {
}
}
// 批量删除成功处理的记录
if len(succeeded) > 0 {
total := len(devices)
persisted := len(succeeded)
failed := total - persisted
// 批量删除成功刷入的记录,失败的保留在 Redis 等待下次重试
if persisted > 0 {
if err := t.rdb.HDel(ctx, "devices", succeeded...).Err(); err != nil {
t.log.Error("redis HDel failed", zap.Int("count", len(succeeded)), zap.Error(err))
t.log.Error("redis HDel failed after persist",
zap.Int("persisted", persisted),
zap.Error(err),
)
} else {
t.log.Info("devices persisted and removed from redis", zap.Int("count", len(succeeded)))
t.log.Info("devices persisted to database and removed from redis",
zap.Int("persisted", persisted),
zap.Int("total", total),
zap.Int("failed", failed),
)
}
}
if failed > 0 {
t.log.Warn("some devices failed to persist, kept in redis for retry",
zap.Int("failed", failed),
zap.Int("total", total),
)
}
}
// persistDevice 处理 user_device 表写入