整合redis
1.导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.配置文件:主要配置信息可以看RedisProperties
spring.redis.host=主机ip #默认是localhost
spring.redis.port=6379
3.测试
@Autowired
RedisTemplate redisTemplate;
@Test
void contextLoads() {
//opsForValue String 数据类型
//opsForList List 列表
// ...
redisTemplate.opsForValue().set("name","liuqing");
redisTemplate.opsForValue().set("age","13");
Object name = redisTemplate.opsForValue().get("name");
System.out.println(name);
}
输出:liuqing