You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
1.1 KiB

  1. package repo
  2. import (
  3. "egg-im/internal/logic/domain/group/model"
  4. "egg-im/pkg/db"
  5. "egg-im/pkg/gerrors"
  6. "strconv"
  7. "time"
  8. "github.com/go-redis/redis"
  9. )
  10. const GroupNoticeKey = "group:notice:"
  11. type groupNoticeCache struct{}
  12. var GroupNoticeCache = new(groupNoticeCache)
  13. // Get 获取群组缓存
  14. func (c *groupNoticeCache) Get(groupId int64) (*model.GroupNotice, error) {
  15. var user model.GroupNotice
  16. err := db.RedisUtil.Get(GroupNoticeKey+strconv.FormatInt(groupId, 10), &user)
  17. if err != nil && err != redis.Nil {
  18. return nil, gerrors.WrapError(err)
  19. }
  20. if err == redis.Nil {
  21. return nil, nil
  22. }
  23. return &user, nil
  24. }
  25. // Set 设置群组缓存
  26. func (c *groupNoticeCache) Set(group *model.GroupNotice) error {
  27. err := db.RedisUtil.Set(GroupNoticeKey+strconv.FormatInt(group.Id, 10), group, 1*time.Hour)
  28. if err != nil {
  29. return gerrors.WrapError(err)
  30. }
  31. return nil
  32. }
  33. // Del 删除群组缓存
  34. func (c *groupNoticeCache) Del(groupId int64) error {
  35. _, err := db.RedisCli.Del(GroupNoticeKey + strconv.FormatInt(groupId, 10)).Result()
  36. if err != nil {
  37. return gerrors.WrapError(err)
  38. }
  39. return nil
  40. }