【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"));

}

}

相关推荐
星梦清河21 小时前
Redis(四):缓存击穿及其解决方案(SpringBoot+mybatis-plus)
spring boot·redis·缓存
FAFU_kyp21 小时前
WebMvcConfig 和 WebSecurityConfig 详解
spring boot·java-ee
往事随风去1 天前
虚拟线程在Spring Boot中的正确使用方式
spring boot
麦兜*1 天前
Spring Boot 应用 Docker 监控:Prometheus + Grafana 全方位监控
spring boot·后端·spring cloud·docker·prometheus
L.EscaRC1 天前
Redisson在Spring Boot中的高并发应用解析
java·spring boot·后端
Naylor1 天前
玩转kafka
spring boot·kafka
摇滚侠1 天前
Spring Boot3零基础教程,StreamAPI 介绍,笔记98
java·spring boot·笔记
摇滚侠1 天前
Spring Boot3零基础教程,StreamAPI 的基本用法,笔记99
java·spring boot·笔记
codingPower1 天前
升级mybatis-plus导致项目启动报错: net.sf.jsqlparser.statement.select.SelectBody
java·spring boot·maven·mybatis
刘一说1 天前
深入理解 Spring Boot Web 开发中的全局异常统一处理机制
前端·spring boot·后端