From 80cafbc839aac8175d47147750156d0ba9283901 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Fri, 27 Dec 2024 20:44:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8C=E6=AD=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/userService.go | 6 +++--- worker/redis.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/service/userService.go b/service/userService.go index ad44cb6..c04f1e1 100644 --- a/service/userService.go +++ b/service/userService.go @@ -121,10 +121,10 @@ func UserSyncDataFromMaster() { fmt.Println("All ClearAllUsers error:", err) return } - worker.SetRedis("user_sync_all", "1") + worker.SetRedisForever("user_sync_all", "1") req.Types = 1 } else { - worker.SetRedis("user_sync_all", "2") + worker.SetRedisForever("user_sync_all", "2") req.Types = 2 } @@ -184,7 +184,7 @@ func UserSyncDataFromMaster() { confirm_req.Confirm = data worker.SyncDataFromMasterReq2(url, confirm_req) } else { - worker.SetRedis("user_sync_all", "2") + worker.SetRedisForever("user_sync_all", "2") } } diff --git a/worker/redis.go b/worker/redis.go index 8eeea4c..3de62e6 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -71,6 +71,17 @@ func SetRedis(key string, value string) bool { return true } +// 设置redis,永久 +func SetRedisForever(key string, value string) bool { + ctx := context.Background() + err := RedisClient.Set(ctx, key, value, 0).Err() + if err != nil { + fmt.Println("Error setting key: %v", err) + return false + } + return true +} + // 设置hash func SetHashWithTime(key string, id int, name, email string, duration time.Duration) bool { //捕获错误,如果错误返回