SpringBoot集成Redis

1.导入依赖

<!--redis-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <version>2.5.4</version>
</dependency>

2.配置redis

#redis配置
spring:
  redis:
    host: 127.0.0.1
    port: 6379

3.测试

@SpringBootTest
class BootApplicationTests {

	@Autowired
	private RedisTemplate redisTemplate;

	@Test
	void contextLoads() throws SQLException {
		redisTemplate.opsForValue().set("name", "jack");
		System.out.println(redisTemplate.opsForValue().get("name"));
	}
}

结果:

image

image

注意:要开启redis服务

posted @ 2021-09-14 10:13  SEVEN_CCODE  阅读(19)  评论(0)    收藏  举报