fix: redis GetHashBatch检查索引是否越界
This commit is contained in:
@@ -277,10 +277,6 @@ func GetHashBatch(source string, keys []string) (map[string]map[string]string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < total; i += batchSize {
|
for i := 0; i < total; i += batchSize {
|
||||||
// 检查索引是否越界
|
|
||||||
if i+batchSize > total {
|
|
||||||
batchSize = total - i
|
|
||||||
}
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(start int) {
|
go func(start int) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@@ -292,8 +288,13 @@ func GetHashBatch(source string, keys []string) (map[string]map[string]string, e
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// 检查索引是否越界
|
||||||
|
end := start + batchSize
|
||||||
|
if end > total {
|
||||||
|
end = total
|
||||||
|
}
|
||||||
pipe := rdb.Pipeline()
|
pipe := rdb.Pipeline()
|
||||||
for _, key := range keys[start : start+batchSize] {
|
for _, key := range keys[start:end] {
|
||||||
pipe.HGetAll(ctx, key)
|
pipe.HGetAll(ctx, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user