优化部分并发问题

This commit is contained in:
Yun
2026-05-27 14:09:08 +08:00
parent 448116dc0d
commit ed326b192d
3 changed files with 31 additions and 11 deletions
+9 -5
View File
@@ -106,6 +106,9 @@ func InitOnce(ctx context.Context, re redis.UniversalClient, keyPrefix string, c
return nil, errors.New("redis client is nil")
}
// 清理 keyPrefix 中的 {} 字符,避免破坏 Redis Cluster hash tag
keyPrefix = sanitizeKeyPrefix(keyPrefix)
ctx, cancel := context.WithCancel(ctx)
u, err := uuid.NewV7()
@@ -307,10 +310,7 @@ func (l *Once) executeTasks() {
case <-l.ctx.Done():
return
case l.workerChan <- struct{}{}:
go func() {
defer func() {
<-l.workerChan
}()
func() {
if l.usePriority && !l.priority.IsLatest(l.ctx) {
time.Sleep(time.Second * 5)
@@ -331,7 +331,7 @@ func (l *Once) executeTasks() {
return
}
// 处理任务
l.processTask(keys[1])
go l.processTask(keys[1])
}()
}
}
@@ -566,6 +566,10 @@ func (l *Once) batchGetTasks() {
// 执行任务
func (l *Once) processTask(key string) {
defer func() {
<-l.workerChan
}()
begin := time.Now()
ctx, cancel := context.WithTimeout(l.ctx, l.timeout)