【SpringBoot】SpringBoot项目中实现数据缓存

步骤01 引入Redis依赖包

<dependency>

<groupId>org.springframework.boot

</groupId>

<artifactId>spring-boot-starter-data-redis

</artifactId>

</dependency>

步骤02 修改配置文件

在application.properties配置文件增加有关Redis的配置:

步骤03 验证测试

@SpringBootTest

public class TestRedisTemplate{

@Autowired

private RedisTemplate redisTemplate;

@Test

public void testString(){

//调用set()方法创建缓存

redisTemplate.opsForVaule().set("hello:redis","hello spring boot");

System.out.println("hello,redis:"+redisTemplate.opsForValue().get("hello:redis"));

}

}

相关推荐
码农学院8 小时前
基于Spring Boot的跨境电商多语言订单管理系统架构设计
java·大数据·spring boot
whyfail14 小时前
前端学 Spring Boot(5):从“你是谁”到“服务真的上线了”
前端·spring boot·后端
2601_9538246114 小时前
【计算机毕业设计】基于Spring Boot的画师接稿平台设计与实现
java·spring boot·后端
稚南城才子,乌衣巷风流16 小时前
Spring Boot 中的 @Lazy 注解:延迟加载的深入解析与实践
java·spring boot·后端
hexu_blog18 小时前
springboot3集成shardingsphere4.0 分表分库
java·spring boot·mybatis
乐观的Terry18 小时前
9、发布系统-Webhook自动发布
java·spring boot·spring·spring cloud·mybatis
PH = 718 小时前
SpringBoot使用自动装配编写Start包
java·spring boot·后端
Q渡劫19 小时前
MinIO 从下载到集成 Spring Boot 完整教程
spring boot·spring·maven
RuoyiOffice20 小时前
超级个体接私活必看:后端+前端+移动端三端一体企业管理系统怎么选(2026)
java·spring boot·vue·uniapp·全栈·企业管理·接私活
wuqingshun31415920 小时前
springBoot是如何通过main方法启动web项目的?
前端·spring boot·后端