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 0e3d99d..3f7ba91 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -225,6 +225,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) // 访问记录 }