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

}

}

相关推荐
ponnylv4 小时前
深入剖析Spring Boot启动流程
java·开发语言·spring boot·spring
cyforkk5 小时前
Spring Boot @RestController 注解详解
java·spring boot·后端
叫我阿柒啊6 小时前
从Java全栈到前端框架:一次真实面试的深度复盘
java·spring boot·typescript·vue·database·testing·microservices
愿你天黑有灯下雨有伞9 小时前
一种基于注解与AOP的Spring Boot接口限流防刷方案
java·spring boot·后端
知识浅谈9 小时前
Redis哨兵模式在Spring Boot项目中的使用与实践
spring boot·redis·bootstrap
lozhyf10 小时前
能发弹幕的简单视频网站
java·spring boot·后端
十八旬11 小时前
苍穹外卖项目实战(day-5完整版)-记录实战教程及问题的解决方法
java·开发语言·spring boot·redis·mysql
chenrui31011 小时前
Spring Boot 和 Spring Cloud: 区别与联系
spring boot·后端·spring cloud
邂逅星河浪漫11 小时前
Spring Boot常用注解-详细解析+示例
java·spring boot·后端·注解
weixin_4569042712 小时前
基于Spring Boot + MyBatis的用户管理系统配置
spring boot·后端·mybatis