Loading

java springboot redis StringRedisTemplate 使用方法-记录

    import org.springframework.data.redis.core.StringRedisTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    
    public static final String CACHE_KEY = "cache:key:";
    
    
    //检查缓存是否存在
    Boolean isExist = this.stringRedisTemplate.hasKey(key);
    
    //获取缓存
    this.stringRedisTemplate.opsForValue().get(key);
    
    //设置缓存
    this.stringRedisTemplate.opsForValue().set(key, "缓存内容", 30, TimeUnit.DAYS);

 

posted @ 2021-11-03 17:24  路闻man  阅读(154)  评论(0编辑  收藏  举报