1、导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2、配置连接
#配置redis
spring.redis.host=127.0.0.1
spring.redis.port=6379
3.测试
中文会乱码是因为还需要序列化
@Autowired
private RedisUtil redisUtil;
@Test
void contextLoads() {
//redisTemplate
//opsForValue 操作字符串
//opsForList 操作List
//RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
//connection.flushAll();
redisTemplate.opsForValue().set("mykey","小明");
System.out.println(redisTemplate.opsForValue().get("mykey"));
}