From ac1b3b0be25fa89a162364e7b674b27901243376 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 31 Jan 2023 10:44:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85db=E5=B1=82=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B8=85=E7=90=86=E9=94=81=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sys/db/core.go | 2 ++ sys/db/dbconn.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/sys/db/core.go b/sys/db/core.go index 59de21e58..e20b35146 100644 --- a/sys/db/core.go +++ b/sys/db/core.go @@ -1,6 +1,7 @@ package db import ( + "sync" "time" ) @@ -24,6 +25,7 @@ type ( //过期数据 ModelDataExpired struct { key string //主key + mu sync.RWMutex //安全锁 keys map[string]struct{} //数据集合 expired time.Time //过期时间 } diff --git a/sys/db/dbconn.go b/sys/db/dbconn.go index 25dda297b..926328ab8 100644 --- a/sys/db/dbconn.go +++ b/sys/db/dbconn.go @@ -61,7 +61,9 @@ func (this *DBConn) UpDateModelExpired(key string, childs map[string]struct{}, e exp.keys = make(map[string]struct{}) } for k, _ := range childs { + exp.mu.Lock() exp.keys[k] = struct{}{} + exp.mu.Unlock() } } exp.expired = time.Now().Add(expired) @@ -107,9 +109,11 @@ func (this *DBConn) scanning() { for _, v := range temp { pipe.Del(ctx, v.key) if v.keys != nil { + v.mu.RLock() for k1, _ := range v.keys { pipe.Del(ctx, k1) } + v.mu.RUnlock() } } if _, err := pipe.Exec(ctx); err != nil {