Class MessagePersistCache

java.lang.Object
com.bytedesk.core.message.MessagePersistCache

@Component public class MessagePersistCache extends Object
消息持久化缓存服务 使用Redis List结构存储消息,支持消息的推入和批量获取
Since:
2024-07-16
Author:
jackning
  • Field Details

    • DEFAULT_PERSIST_KEY

      private static final String DEFAULT_PERSIST_KEY
      See Also:
    • EXPIRE_TIME_DAYS

      private static final long EXPIRE_TIME_DAYS
      See Also:
    • stringRedisTemplate

      private final org.springframework.data.redis.core.StringRedisTemplate stringRedisTemplate
  • Constructor Details

    • MessagePersistCache

      public MessagePersistCache()
  • Method Details

    • init

      @PostConstruct public void init()
      初始化Redis配置
    • pushForPersist

      public void pushForPersist(String messageJSON)
      向默认持久化列表推送消息
      Parameters:
      messageJSON - 消息JSON字符串
    • getListForPersist

      public List<String> getListForPersist()
      从默认持久化列表获取所有消息
      Returns:
      消息列表,如果列表为空则返回空列表
    • push

      public void push(String listKey, String messageJSON)
      向指定列表推送消息
      Parameters:
      listKey - 列表键名
      messageJSON - 消息JSON字符串
    • getList

      public List<String> getList(String listKey)
      获取指定列表的所有消息并清空列表
      Parameters:
      listKey - 列表键名
      Returns:
      消息列表,如果列表为空则返回空列表
    • clearCache

      public void clearCache(String listKey)
      清空指定列表的缓存
      Parameters:
      listKey - 列表键名