fix: 修复 Redis 数据处理中的索引越界和数据格式校验

This commit is contained in:
TsMask
2025-03-08 10:29:46 +08:00
parent c27b602e0d
commit d2680437d4
3 changed files with 15 additions and 10 deletions

View File

@@ -261,9 +261,9 @@ func GetHashBatch(source string, keys []string) (map[string]map[string]string, e
}
// 数据源
rdb := DefaultRDB()
if source != "" {
rdb = RDB(source)
rdb := RDB(source)
if rdb == nil {
return result, fmt.Errorf("redis not client")
}
// 创建一个有限的并发控制信号通道
@@ -288,8 +288,13 @@ func GetHashBatch(source string, keys []string) (map[string]map[string]string, e
wg.Done()
}()
// 检查索引是否越界
end := start + batchSize
if end > total {
end = total
}
pipe := rdb.Pipeline()
for _, key := range keys[start : start+batchSize] {
for _, key := range keys[start:end] {
pipe.HGetAll(ctx, key)
}

View File

@@ -49,13 +49,13 @@ func (r *UDMAuthUser) dataByRedis(imsi, neId string) []model.UDMAuthUser {
}
for k, m := range mkv {
if k == "-" {
if len(k) != 20 {
continue
}
// 跳过-号数据 ausf:360000100000130
imsi := k[5:]
if strings.Contains(imsi, "-") {
imsi, hasPrefix := strings.CutPrefix(k, "ausf:")
if strings.Contains(imsi, "-") || !hasPrefix {
continue
}

View File

@@ -50,13 +50,13 @@ func (r *UDMSubUser) dataByRedis(imsi, neId string) []model.UDMSubUser {
}
for k, m := range mkv {
if k == "-" {
if len(k) != 22 {
continue
}
// 跳过-号数据 udm-sd:360000100000130
imsi := k[7:]
if strings.Contains(imsi, "-") {
imsi, hasPrefix := strings.CutPrefix(k, "udm-sd:")
if strings.Contains(imsi, "-") || !hasPrefix {
continue
}