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

}

}

相关推荐
考虑考虑2 小时前
@FilterRegistration和@ServletRegistration注解
spring boot·后端·spring
一只叫煤球的猫2 小时前
🔥 同事混用@Transactional和TransactionTemplate被我怼了,三种事务管理到底怎么选?
java·spring boot·后端
华子w9089258599 天前
基于 SpringBoot+JSP 的医疗预约与诊断系统设计与实现
java·spring boot·后端
java—大象9 天前
基于java SSM的房屋租赁系统设计和实现
java·开发语言·数据库·spring boot·layui·mybatis
Mutig_s9 天前
Spring Boot动态数据源切换:优雅实现多数据源管理
java·数据库·spring boot·后端·mybatis
weixin_425023009 天前
Spring Boot使用MCP服务器
服务器·spring boot·后端·spring ai·mcp
weixin_438335409 天前
Spring Boot:运用Redis统计用户在线数量
java·spring boot·redis
超级小忍9 天前
Spring Boot 集成 Apache Kafka 实战指南
spring boot·kafka·apache
程序员小刚10 天前
基于SpringBoot + Vue 的网上拍卖系统
vue.js·spring boot·后端