fix: redis批量获得缓存数据独立上下文

This commit is contained in:
TsMask
2024-11-08 16:54:27 +08:00
parent 26b950c919
commit 103af4a999

View File

@@ -265,7 +265,6 @@ func GetHashBatch(source string, keys []string) (map[string]map[string]string, e
if source != "" {
rdb = RDB(source)
}
ctx := context.Background()
// 创建一个有限的并发控制信号通道
sem := make(chan struct{}, 10)
@@ -280,11 +279,13 @@ func GetHashBatch(source string, keys []string) (map[string]map[string]string, e
for i := 0; i < total; i += batchSize {
wg.Add(1)
go func(start int) {
ctx := context.Background()
// 并发控制,限制同时执行的 Goroutine 数量
sem <- struct{}{}
defer func() {
wg.Done()
<-sem
ctx.Done()
wg.Done()
}()
pipe := rdb.Pipeline()