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

}

}

相关推荐
彭于晏Yan2 小时前
LangChain4j实战三:图像模型
java·spring boot·后端·langchain
无尽的沉默2 小时前
使用Thymeleaf配置国际化页面(语言切换)
前端·spring boot
my_styles3 小时前
window系统安装/配置Nginx
服务器·前端·spring boot·nginx
洋洋技术笔记3 小时前
Spring Boot自动装配原理
java·spring boot
迪巴拉15254 小时前
基于Springboot+Vue的制造业采购管理系统
vue.js·spring boot·后端
qq_12498707534 小时前
基于springboot+vue的热门文创内容推荐平台(源码+论文+部署+安装)
vue.js·spring boot·后端·spring·毕业设计·计算机毕设
鹿角片ljp5 小时前
短信登录:基于 Session 实现(黑马点评实战)
java·服务器·spring boot·mybatis
计算机学姐7 小时前
基于SpringBoot的服装购物商城销售系统【协同过滤推荐算法+数据可视化统计】
java·vue.js·spring boot·mysql·信息可视化·mybatis·推荐算法
程序员阿明7 小时前
spring security6+spring boot 3.5.9最新版本集成oauth2.1
android·spring boot·spring