1、引入maven依赖
<!-- 引入 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.188 #配置自己的redis服务ip
port: 6379
password: 123456! #配置自己的redis密码
3、controller测试
@Autowired
private RedisTemplate redisTemplate;
//设置某个key
redisTemplate.opsForValue().set(key, value);
//获取某个key
(String)redisTemplate.opsForValue().get(key);
//删除某个key
redisTemplate.delete(key);