Spring boot + Redis

1.  pom.xml 配置redis依赖
 <!-- redis依赖包 -->
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>

2. application.properties中标下redis db 的信息
# REDIS (RedisProperties)
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=localhost
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=

3.写一个测试来测试下,加上断言判断,也可以通过cmd获取aaa对应的值
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class TestReadis {

@Autowired
private StringRedisTemplate stringRedisTemplate;

@Test
public void test() throws Exception {

// 保存字符串
stringRedisTemplate.opsForValue().set("aaa", "111");
Assert.assertEquals("111", stringRedisTemplate.opsForValue().get("aaa"));

}

}

 




posted @ 2018-12-28 11:28  巴黎爱工作  阅读(229)  评论(0编辑  收藏  举报