SpringBoot引入Redis很简单,添加以下注解:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
然后在application.yml中添加Redis配置:
spring:
redis:
host: localhost
database: 1
port: 6379
注:此处有一些额外的配置,比如password等,我这里为省事就不写了。
下面我们可以编写测试类了:
package com.eknown;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis