Files
chatgpt-dingtalk/pkg/cache/user_requese.go
T
Ashing Zheng 5300bfa297 ci: add lint workflow (#283)
* ci: add lint

Signed-off-by: ashing <axingfly@gmail.com>

* fix: add timeout

Signed-off-by: ashing <axingfly@gmail.com>

* fix: EOL

Signed-off-by: ashing <axingfly@gmail.com>

* fix: EOL

Signed-off-by: ashing <axingfly@gmail.com>

---------

Signed-off-by: ashing <axingfly@gmail.com>
2024-02-23 18:14:56 +08:00

23 lines
590 B
Go

package cache
import (
"time"
)
// SetUseRequestCount 设置用户请求次数
func (s *UserService) SetUseRequestCount(userId string, current int) {
expiration := time.Now().Add(time.Hour * 24).Truncate(time.Hour * 24)
duration := time.Until(expiration)
// 设置缓存失效时间为第二天零点
s.cache.Set(userId+"_request", current, duration)
}
// GetUseRequestCount 获取当前用户已请求次数
func (s *UserService) GetUseRequestCount(userId string) int {
sessionContext, ok := s.cache.Get(userId + "_request")
if !ok {
return 0
}
return sessionContext.(int)
}