一.创建springboot项目

二.引入2个依赖

<!-- redis依赖-->这个已经引入了,因为创建的时候勾选了
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- common-pool连接池依赖-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
三.写yml配置文件
记得把文件后缀改为yml
spring:
redis:
host: 127.0.0.1
port: 6380
password: 123321
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
max-wait: 1000ms

四.注解注入RedisTemplate
@Autowired private RedisTemplate redisTemplate;
五.然后就可以使用了
@SpringBootTest
class RedisDemoApplicationTests {
@Autowired
private RedisTemplate redisTemplate;
@Test
void contextLoads() {
redisTemplate.opsForValue().set("name","lisi");
Object name =redisTemplate.opsForValue().get("name");
System.out.println("name = " + name);
}
}











![2023年中国BaaS行业发展概况及未来发展趋势分析:未来多链支持和发展将是BaaS平台发展重点方向[图]](https://img-blog.csdnimg.cn/img_convert/74ec388500f2c7e01ec65fd26271b463.png)





![2023年中国电动汽车充换电站行业现状分析:随车配建私人充电桩增量持续上升[图]](https://img-blog.csdnimg.cn/img_convert/6402c788385fd56b42a5702e6de52bc0.png)

