zl程序教程

您现在的位置是:首页 >  后端

当前栏目

缓存预热

缓存 预热
2023-06-13 09:11:26 时间

我们Redis会有一些热点数据,我们需要在项目启动时,添加一些热点缓存数据!

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class DiyDataInit implements InitializingBean {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("数据初始化中...");
        try {
            redisTemplate.opsForValue().set("初始化基本数据","ok");
        }catch (Exception e){
            log.error("数据初始化失败",e.getMessage());
        }
        log.info("数据初始化完成...");
    }
}

特殊说明: 以上文章,均是我实际操作,写出来的笔记资料,不会盗用别人文章!烦请各位,请勿直接盗用!转载记得标注来源!