通常使用spring data redis框架的时候对缓存的操作使用org.springframework.data.redis.core.RedisTemplate
RedisTemplate中有以下方法
public Boolean expire(K key, final long timeout, final TimeUnit unit)可以知道我们可以通过缓存的key值,设置缓存的过期时间
例如缓存设置过期时间为60秒
redisTemplate.expire("testKey",60l,java.util.concurrent.TimeUnit.SECONDS);
https://www.syntaxspace.com/article/190.html
评论