1.
private static final Logger LOGGER = LoggerFactory.getLogger(HttpServiceImpl.class);
@Resource
private RedisTemplate redisTemplate;
@PostMapping("delete") public Result delete(boolean flag) { //设置存储的过期时间 redisTemplate.opsForValue().set("hha","dada",50, TimeUnit.SECONDS); //设置不过期时间的Key redisTemplate.opsForValue().set("kk","hhh"); System.out.println(redisTemplate.opsForValue().get("kk")); //删除指定的key redisTemplate.delete("kk"); studentService.removeById(2); return flag ?Result.ok("第一个"):Result.fail("第二个"); }
过期时间的查看命令 ttl name
在图形化界面中也可以查看redis的过期时间