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