util.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package entity
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
  4. "app.yhyue.com/moapp/jybase/redis"
  5. "encoding/json"
  6. "fmt"
  7. )
  8. const (
  9. Date_Full_Layout = "2006-01-02 15:04:05"
  10. SOCIALIZE_CHAT_SESSION = "socialize_chat_session"
  11. SOCIALIZE_MESSAGE = "socialize_message"
  12. SOCIALIZE_MESSAGE_MAILBOX = "socialize_message_mailbox"
  13. SOCIALIZE_TENANT_ROBOT = "socialize_tenant_robot"
  14. BASE_USER = "base_user"
  15. )
  16. const (
  17. SUCCESS_CODE = int64(0)
  18. ERROR_CODE = int64(1)
  19. )
  20. const redisModule = "msgCount"
  21. type SubPush struct {
  22. Data []*message.Messages `json:"data"`
  23. Count int64 `json:"count"`
  24. }
  25. // 获取redis key
  26. func todayKey(userId string) string {
  27. return fmt.Sprintf("%s_%s", "messageCount", userId)
  28. }
  29. func GetData(userId string) (*SubPush, error) {
  30. pc_a, err := redis.GetNewBytes(redisModule, todayKey(userId))
  31. if err != nil {
  32. return nil, err
  33. }
  34. if pc_a == nil {
  35. return nil, nil
  36. }
  37. var p *SubPush
  38. if err := json.Unmarshal(*pc_a, &p); err != nil {
  39. return nil, err
  40. }
  41. return p, nil
  42. }
  43. func SetData(userId string, data map[string]interface{}, survivalTime int) {
  44. redis.Put(redisModule, todayKey(userId), data, survivalTime)
  45. }