- 在pom.xml中添加依赖即可
<!--redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
- 在application.xml中添加redis配置
spring:
redis:
port: 6379
host: localhost
- 测试是否整合成功,在pom.xml中添加junit依赖
<!--junit依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
- 在test\java下新建包com.cxsbg包,在cxsbg包下新建测试类
package com.cxsbg;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
@SpringBootTest
public class WebTest {
@Autowired
private StringRedisTemplate redisTemplate;
@Test
public void testRedis(){
redisTemplate.opsForValue().set("name","cxsbg");
}
@Test
public void testRedisGet(){
String name = redisTemplate.opsForValue().get("name");
System.out.println(name);
}
}