From 01419691f2e963c088d5bf4ae87e34bc31b5435b Mon Sep 17 00:00:00 2001 From: dengbiao Date: Fri, 13 Dec 2024 19:35:16 +0800 Subject: [PATCH] update --- app/hdl/comm/hdl_comm.go | 18 ++++++++++-------- app/router/router.go | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/hdl/comm/hdl_comm.go b/app/hdl/comm/hdl_comm.go index eaf413a..7fa462a 100644 --- a/app/hdl/comm/hdl_comm.go +++ b/app/hdl/comm/hdl_comm.go @@ -107,8 +107,16 @@ func AccessRecords(c *gin.Context) { user := svc.GetUser(c) date := time.Now().Format("2006-01-02") - cacheKey := fmt.Sprintf(md.UserAccessRecordsKey, date, req.Index) + if !cache.Exists(cacheKey) { + ttl := 24 * 60 * 60 // 记录保存24小时 + _, err := cache.SetEx(cacheKey, nil, ttl) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + } + get, err1 := cache.GetBit(cacheKey, user.Id) if err1 != nil || get == 0 { recordsDb := implement.NewEggAccessRecordsDb(db.Db) @@ -128,14 +136,8 @@ func AccessRecords(c *gin.Context) { return } } - ttl := 24 * 60 * 60 // 记录保存24小时 - _, err = cache.SetBit(cacheKey, user.Id, 1) - if err != nil { - e.OutErr(c, e.ERR, err.Error()) - return - } - _, err = cache.Expire(cacheKey, ttl) + _, err = cache.SetBit(cacheKey, user.Id, 1) if err != nil { e.OutErr(c, e.ERR, err.Error()) return diff --git a/app/router/router.go b/app/router/router.go index 2662d58..d7be9d7 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -224,6 +224,6 @@ func rCircleFriends(r *gin.RouterGroup) { } func rComm(r *gin.RouterGroup) { - r.POST("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL - r.GET("/accessRecords", comm.AccessRecords) // 访问记录 + r.POST("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL + r.POST("/accessRecords", comm.AccessRecords) // 访问记录 }