From d2680437d4f804d04c44afe6d534d937d448000d Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Sat, 8 Mar 2025 10:29:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Redis=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=84=E7=90=86=E4=B8=AD=E7=9A=84=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E8=B6=8A=E7=95=8C=E5=92=8C=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/redis/redis.go | 13 +++++++++---- src/modules/network_data/service/udm_auth.go | 6 +++--- src/modules/network_data/service/udm_sub.go | 6 +++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/framework/redis/redis.go b/src/framework/redis/redis.go index eb361217..cc5a6c03 100644 --- a/src/framework/redis/redis.go +++ b/src/framework/redis/redis.go @@ -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) } diff --git a/src/modules/network_data/service/udm_auth.go b/src/modules/network_data/service/udm_auth.go index 807b8be2..c48b5285 100644 --- a/src/modules/network_data/service/udm_auth.go +++ b/src/modules/network_data/service/udm_auth.go @@ -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 } diff --git a/src/modules/network_data/service/udm_sub.go b/src/modules/network_data/service/udm_sub.go index 7288c108..26020dea 100644 --- a/src/modules/network_data/service/udm_sub.go +++ b/src/modules/network_data/service/udm_sub.go @@ -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 }