首先,实体要先实现Serializable
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
注入redis
@Autowired
private RedisTemplate redisTemplate;
存入redis
redisTemplate.opsForValue().set("term_"+id,term,1, TimeUnit.HOURS);
从redis获取
Term redisTerm = (Term)redisTemplate.opsForValue().get("term_" + id);
从redis删除
redisTemplate.delete("term_"+id);