cache.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "context"
  4. daoAnchorV1 "go-common/app/service/live/dao-anchor/api/grpc/v1"
  5. "go-common/library/log"
  6. )
  7. func (d *Dao) SetRecPoolCache(ctx context.Context, key string, list string, expire int) (err error) {
  8. log.Info("[SetRecPoolCache]key: %s", key)
  9. rconn := d.redis.Get(ctx)
  10. defer rconn.Close()
  11. if _, err = rconn.Do("SET", key, list, "EX", expire); err != nil {
  12. log.Error("[SetRecPoolCache]redis.Set error(%v)", err)
  13. }
  14. return
  15. }
  16. func (d *Dao) SetRecInfoCache(ctx context.Context, list map[int64]*daoAnchorV1.RoomData) (err error) {
  17. rconn := d.redis.Get(ctx)
  18. defer rconn.Close()
  19. //rconn.Send("MULTI")
  20. for roomId, roomData := range list {
  21. if roomData == nil {
  22. continue
  23. }
  24. key, expire := d.getRecInfoKey(roomId)
  25. rconn.Send("HMSET", key, "room_id", roomData.RoomId, "uid", roomData.Uid, "title", roomData.Title, "popularity_count", roomData.PopularityCount, "Keyframe", roomData.Keyframe, "cover", roomData.Cover, "parent_area_id", roomData.ParentAreaId, "parent_area_name", roomData.ParentAreaName, "area_id", roomData.AreaId, "area_name", roomData.AreaName)
  26. rconn.Send("EXPIRE", key, expire)
  27. }
  28. if err = rconn.Flush(); err != nil {
  29. log.Error("[SetRecInfoCache]redis.Set error(%v)", err)
  30. }
  31. for _, roomData := range list {
  32. if roomData == nil {
  33. continue
  34. }
  35. rconn.Receive()
  36. rconn.Receive()
  37. }
  38. return
  39. }