在Springboot项目中开箱即用Redis

添加POM依赖

1
2
3
4
5
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>

配置yml

1
2
3
4
5
6
7
spring:
redis:
host: 127.0.0.1
port: 6379
password: <PASSWORD>
timeout: 5000

注入

1
2
3
4
5
6
@Autowired
private RedisTemplate redisTemplate;

public void test() {
redisTemplate.opsForValue().set("test", "test");
}

即可在Redis中查看数据