RedisKeyConstants.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.zhentao.constant;
  2. /**
  3. * Redis缓存Key常量
  4. */
  5. public class RedisKeyConstants {
  6. /**
  7. * 红娘详情缓存Key前缀
  8. * 格式:matchmaker:detail:{matchmakerId}
  9. */
  10. public static final String MATCHMAKER_DETAIL = "matchmaker:detail:";
  11. /**
  12. * 红娘列表缓存Key前缀
  13. * 格式:matchmaker:list:{type}:{level}:{provinceId}:{cityId}:{pageNum}:{pageSize}
  14. */
  15. public static final String MATCHMAKER_LIST = "matchmaker:list:";
  16. /**
  17. * 全职红娘列表缓存Key前缀
  18. * 格式:matchmaker:formal:{pageNum}:{pageSize}
  19. */
  20. public static final String MATCHMAKER_FORMAL_LIST = "matchmaker:formal:";
  21. /**
  22. * 热门红娘列表缓存Key
  23. */
  24. public static final String MATCHMAKER_HOT_LIST = "matchmaker:hot:list";
  25. /**
  26. * 红娘详情缓存过期时间(秒)- 1小时
  27. */
  28. public static final long MATCHMAKER_DETAIL_EXPIRE = 3600;
  29. /**
  30. * 红娘列表缓存过期时间(秒)- 30分钟
  31. */
  32. public static final long MATCHMAKER_LIST_EXPIRE = 1800;
  33. /**
  34. * 热门红娘列表缓存过期时间(秒)- 30分钟
  35. */
  36. public static final long MATCHMAKER_HOT_EXPIRE = 1800;
  37. /**
  38. * 构建红娘详情缓存Key
  39. */
  40. public static String buildMatchmakerDetailKey(Integer matchmakerId) {
  41. return MATCHMAKER_DETAIL + matchmakerId;
  42. }
  43. /**
  44. * 构建红娘列表缓存Key
  45. */
  46. public static String buildMatchmakerListKey(Integer type, Integer level, Integer provinceId,
  47. Integer cityId, String keyword, Integer pageNum, Integer pageSize) {
  48. // 将keyword转换为缓存键的一部分,如果为空则使用"all"
  49. String keywordPart = (keyword != null && !keyword.trim().isEmpty()) ? keyword.trim() : "all";
  50. return MATCHMAKER_LIST +
  51. (type != null ? type : "all") + ":" +
  52. (level != null ? level : "all") + ":" +
  53. (provinceId != null ? provinceId : "all") + ":" +
  54. (cityId != null ? cityId : "all") + ":" +
  55. keywordPart + ":" +
  56. pageNum + ":" + pageSize;
  57. }
  58. /**
  59. * 构建全职红娘列表缓存Key
  60. */
  61. public static String buildFormalListKey(Integer pageNum, Integer pageSize) {
  62. return MATCHMAKER_FORMAL_LIST + pageNum + ":" + pageSize;
  63. }
  64. }