redisKey.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "go-common/app/service/live/dao-anchor/api/grpc/v1"
  7. "go-common/library/log"
  8. )
  9. type redisKeyResp struct {
  10. RedisKey string `json:"redis_key"`
  11. TimeOut int `json:"time_out"`
  12. }
  13. //RoomRecordListForLive 房间侧开播记录相关历史数据,存3天
  14. func (d *Dao) LRoomLiveRecordList(content string, roomId int64, liveTime int64) (resp *redisKeyResp) {
  15. resp = &redisKeyResp{}
  16. if liveTime <= 0 {
  17. roomInfo, err := d.FetchRoomByIDs(context.TODO(), &v1.RoomByIDsReq{RoomIds: []int64{roomId}, Fields: []string{"live_start_time"}})
  18. if err != nil || roomInfo.RoomDataSet == nil {
  19. log.Error("LRoomLiveRecordList_err:err=%v;info=%v", err, roomInfo)
  20. return
  21. }
  22. liveTime = roomInfo.RoomDataSet[roomId].LiveStartTime
  23. }
  24. contentType := content + "_" + strconv.Itoa(int(liveTime))
  25. resp.RedisKey = fmt.Sprintf(contentType+"_list_%d", roomId)
  26. resp.TimeOut = 24 * 60 * 60 * 3
  27. return
  28. }
  29. //RoomRecordList 房间侧记录相关历史数据,存1天
  30. func (d *Dao) LRoomRecordList(contentType string, roomId int64) (resp *redisKeyResp) {
  31. resp = &redisKeyResp{}
  32. resp.RedisKey = fmt.Sprintf(contentType+"_list_%d", roomId)
  33. resp.TimeOut = 24 * 60 * 60
  34. return
  35. }
  36. //RoomRecordCurrent 房间侧实时数据记录,存一个小时
  37. func (d *Dao) SRoomRecordCurrent(content string, roomId int64) (resp *redisKeyResp) {
  38. resp = &redisKeyResp{}
  39. resp.RedisKey = fmt.Sprintf(content+"_key_%d", roomId)
  40. resp.TimeOut = 60 * 60
  41. return
  42. }
  43. //主播侧开播记录相关历史数据,存3天
  44. func (d *Dao) LUserLiveRecordList(content string, uid int64, liveTime int64) (resp *redisKeyResp) {
  45. resp = &redisKeyResp{}
  46. if liveTime <= 0 {
  47. roomInfo, err := d.FetchRoomByIDs(context.TODO(), &v1.RoomByIDsReq{Uids: []int64{uid}, Fields: []string{"live_start_time"}})
  48. if err != nil {
  49. log.Error("LRoomLiveRecordList_err:err=%v;info=%v", err, roomInfo)
  50. return
  51. }
  52. }
  53. contentType := content + "_" + strconv.Itoa(int(liveTime))
  54. resp.RedisKey = fmt.Sprintf(contentType+"_list_%d", uid)
  55. resp.TimeOut = 24 * 60 * 60 * 3
  56. return
  57. }
  58. //主播侧记录相关历史数据,存1天
  59. func (d *Dao) LUserRecordList(contentType string, uid int64) (resp *redisKeyResp) {
  60. resp = &redisKeyResp{}
  61. resp.RedisKey = fmt.Sprintf(contentType+"_list_%d", uid)
  62. resp.TimeOut = 24 * 60 * 60
  63. return
  64. }
  65. //UserRecordCurrent 主播侧实时数据记录,存一个小时
  66. func (d *Dao) SUserRecordCurrent(content string, uid int64) (resp *redisKeyResp) {
  67. resp = &redisKeyResp{}
  68. resp.RedisKey = fmt.Sprintf(content+"_key_%d", uid)
  69. resp.TimeOut = 60 * 60
  70. return
  71. }