<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
spring: redis: host: 127.0.0.1 port: 6379 # password: 111 没有密码就不配置
咱们来进行测试:
@RunWith(SpringRunner.class) @SpringBootTest class TestredisApplicationTests { @Autowired private RedisTemplate<String,String> redisTemplate; @Test void testSet(){ redisTemplate.opsForValue().set("isKey","isValue"); System.out.println(redisTemplate.opsForValue().get("isKey")); } @Test void testDelete(){ redisTemplate.delete("isKey"); System.out.println("删除成功"); } }
运行testSet测试方法会看到:
运行testDelete测试方法会看到:
以上就是SpringBoot整合Redis的简易内容