user_requese.go 440 B

12345678910111213141516171819
  1. package cache
  2. import (
  3. "time"
  4. )
  5. // SetUseRequestCount 设置用户请求次数
  6. func (s *UserService) SetUseRequestCount(userId string, current int) {
  7. s.cache.Set(userId+"_request", current, time.Hour*24)
  8. }
  9. // GetUseRequestCount 获取当前用户已请求次数
  10. func (s *UserService) GetUseRequestCount(userId string) int {
  11. sessionContext, ok := s.cache.Get(userId + "_request")
  12. if !ok {
  13. return 0
  14. }
  15. return sessionContext.(int)
  16. }