BusinessMessageManager.java 1.0 KB

1234567891011121314151617181920212223242526272829
  1. package com.pj.project.tb_business;
  2. import com.pj.utils.cache.RedisUtil;
  3. import org.springframework.stereotype.Component;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.stream.Collectors;
  7. @Component
  8. public class BusinessMessageManager {
  9. private static String MES_PREFIX = "b_m:";
  10. private static long EXP_TIME_SECOND = 24 * 60;
  11. public static void set(String customerId, String content) {
  12. List<Object> list = RedisUtil.forListGet(MES_PREFIX + customerId);
  13. List<String>checkList=list.stream().map(Object::toString).collect(Collectors.toList());
  14. if (checkList.contains(content)) {
  15. return;
  16. }
  17. RedisUtil.forListAdd(MES_PREFIX + customerId, content);
  18. }
  19. public static List<String> get(String customerId) {
  20. List<Object> list = RedisUtil.forListGet(MES_PREFIX + customerId);
  21. RedisUtil.forListRemove(MES_PREFIX+customerId);
  22. return list == null ? Collections.emptyList() : list.stream().map(Object::toString).collect(Collectors.toList());
  23. }
  24. }