1. 引入 redis 依赖
<!-- 引入 redis 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2. 配置redis
spring:
redis:
database: 1
host: 192.168.1.191
port: 6379
password: imooc
3. controller 测试
@Autowired
private RedisTemplate redisTemplate;
redisTemplate.opsForValue().set(key, value);
(String)redisTemplate.opsForValue().get(key);
redisTemplate.delete(key);