Spring boot简单接入Redis
1.pom文件中引入redis
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.yml文件redis属性配置
spring:
redis:
host: 120.46.40.0
port: 6379
redis在搭建时没有设置账号密码, 所以不需要配置
3.测试类进行添加数据测试
@Resource
private StringRedisTemplate stringRedisTemplate;
@Test
void redisTest() {
ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
stringStringValueOperations.set("zj","zjj");
String zj = stringStringValueOperations.get("zj");
System.out.printf("数据="+zj);
}
4.测试结果