user_chatid.go 644 B

12345678910111213141516171819202122
  1. package cache
  2. import "time"
  3. // SetAnswerID 设置用户获得答案的ID
  4. func (s *UserService) SetAnswerID(userId, chattitle string, current uint) {
  5. s.cache.Set(userId+"_"+chattitle, current, time.Hour*24)
  6. }
  7. // GetAnswerID 获取当前用户获得答案的ID
  8. func (s *UserService) GetAnswerID(userId, chattitle string) uint {
  9. sessionContext, ok := s.cache.Get(userId + "_" + chattitle)
  10. if !ok {
  11. return 0
  12. }
  13. return sessionContext.(uint)
  14. }
  15. // ClearUserSessionContext 清空GPT上下文,接收文本中包含 SessionClearToken
  16. func (s *UserService) ClearAnswerID(userId, chattitle string) {
  17. s.cache.Delete(userId + "_" + chattitle)
  18. }