mc.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package roomAdmin
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/service/live/xuser/model"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/log"
  8. "go-common/library/stat/prom"
  9. )
  10. // AddCacheNoneUser write an flag in cache represents empty
  11. func (d *Dao) AddCacheNoneUser(c context.Context, uid int64) (err error) {
  12. conn := d.mc.Get(c)
  13. defer conn.Close()
  14. key := KeyUser(uid)
  15. var roomAdmins []model.RoomAdmin
  16. roomAdmins = append(roomAdmins, model.RoomAdmin{
  17. Id: -1,
  18. })
  19. item := &memcache.Item{Key: key, Object: roomAdmins, Expiration: d.RoomAdminExpire, Flags: memcache.FlagJSON | memcache.FlagGzip}
  20. if err = conn.Set(item); err != nil {
  21. prom.BusinessErrCount.Incr("mc:AddCacheRoomAdminAnchor")
  22. log.Errorv(c, log.KV("AddCacheRoomAdminAnchor", fmt.Sprintf("%+v", err)), log.KV("key", key))
  23. return
  24. }
  25. return
  26. }
  27. // AddCacheNoneRoom write an flag in cache represents empty
  28. func (d *Dao) AddCacheNoneRoom(c context.Context, uid int64) (err error) {
  29. conn := d.mc.Get(c)
  30. defer conn.Close()
  31. key := KeyRoom(uid)
  32. var roomAdmins []model.RoomAdmin
  33. roomAdmins = append(roomAdmins, model.RoomAdmin{
  34. Id: -1,
  35. })
  36. item := &memcache.Item{Key: key, Object: roomAdmins, Expiration: d.RoomAdminExpire, Flags: memcache.FlagJSON | memcache.FlagGzip}
  37. if err = conn.Set(item); err != nil {
  38. prom.BusinessErrCount.Incr("mc:AddCacheRoomAdminAnchor")
  39. log.Errorv(c, log.KV("AddCacheRoomAdminAnchor", fmt.Sprintf("%+v", err)), log.KV("key", key))
  40. return
  41. }
  42. return
  43. }
  44. //
  45. //// GetByUserMC .
  46. //func (d *Dao) GetByUserMC(c context.Context, uid int64) (rst []*model.RoomAdmin, hit int64, err error) {
  47. // hit = 0
  48. // key := d.getUserKey(uid)
  49. // conn := d.mc.Get(c)
  50. // defer conn.Close()
  51. //
  52. // reply, err := conn.Get(key)
  53. // //spew.Dump("GetByUserMC1", reply, err)
  54. //
  55. // if err != nil {
  56. // if err == memcache.ErrNotFound {
  57. // err = nil
  58. // return
  59. // }
  60. // log.Error("GetByUserMC get (%v) error(%v)", key, err)
  61. // return
  62. // }
  63. //
  64. // hit = 1
  65. //
  66. // if reply.Object == nil {
  67. // return nil, hit, err
  68. // }
  69. //
  70. // if err = conn.Scan(reply, rst); err != nil {
  71. // log.Error("GetByUserMC Scan (%+v) error(%v)", reply, err)
  72. // }
  73. //
  74. // //spew.Dump("GetByUserMC2", rst, err)
  75. // return
  76. //}
  77. //
  78. //// SetByUserMc .
  79. //func (d *Dao) SetByUserMc(c context.Context, uid int64, rst []*model.RoomAdmin) (err error) {
  80. // key := d.getUserKey(uid)
  81. // conn := d.mc.Get(c)
  82. // defer conn.Close()
  83. //
  84. // err = conn.Set(&memcache.Item{
  85. // Key: key,
  86. // Object: rst,
  87. // Flags: memcache.FlagJSON,
  88. // Expiration: mcExpire,
  89. // })
  90. //
  91. // //spew.Dump("SetByUserMc", err)
  92. // if err != nil {
  93. // log.Error("SetByUserMc set(%v) value (%+v) error (%v)", key, rst, err)
  94. // return
  95. // }
  96. // return
  97. //}