我们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("数据初始化完成...");
    }
}
特殊说明:
上述文章均是作者实际操作后产出。烦请各位,请勿直接盗用!转载记得标注原文链接:www.zanglikun.com
第三方平台不会及时更新本文最新内容。如果发现本文资料不全,可访问本人的Java博客搜索:标题关键字。以获取全部资料 ❤