28 lines
810 B
Go
28 lines
810 B
Go
package redisdao
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/global"
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/redismodel"
|
|
)
|
|
|
|
// viewCountTTL 访问计数 key 的过期时间,避免长期驻留导致内存无界增长。
|
|
const viewCountTTL = 7 * 24 * time.Hour
|
|
|
|
// ClosetShareViewIncr 衣柜分享访问计数 +1,返回最新值
|
|
func ClosetShareViewIncr(ctx context.Context, shareUUID string) (int64, error) {
|
|
ctx, span := global.Tracer.Start(ctx, "redisdao.ClosetShareViewIncr")
|
|
defer span.End()
|
|
|
|
key := fmt.Sprintf(redismodel.KeyClosetShareView, shareUUID)
|
|
val, err := quotaDailyIncrScript.Run(ctx, global.RedisEngine, []string{key}, int(viewCountTTL.Seconds())).Int64()
|
|
if err != nil {
|
|
span.RecordError(err)
|
|
return 0, err
|
|
}
|
|
return val, nil
|
|
}
|