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

}

}

相关推荐
立心者011 小时前
SpringBoot中使用TOTP实现MFA(多因素认证)
java·spring boot·后端
QQ_216962909614 小时前
Spring Boot 养老院管理系统:从入住、护理到费用结算的全流程实现(源码可领)
java·spring boot·后端
xxwl58518 小时前
数据库后端接口测试报告
spring boot·mysql·tomcat
zzzzzz31019 小时前
别让大模型直接碰业务:我在 Spring Boot 里给 AI 操作加了一道“可拒绝的闸门”
人工智能·spring boot·spring
知彼解己19 小时前
Java 版本演进
java·开发语言·spring boot
夜郎king19 小时前
SpringBoot+PostgreSQL + 硅基流动大模型从零搭建 Text-to-SQL 智能问答系统
spring boot·postgresql·text-to-sql·llm大模型
就改了20 小时前
MyBatis核心类用法详解
java·spring boot·后端·mybatis
DarLing丶张皇20 小时前
【源码】JeecgBoot导出Excel模板
java·spring boot
paopaokaka_luck2 天前
基于springboot3+vue3的智能文库平台(AI智能搜索、AI智能汇总、实时在线状态展示、多格式文档预览与富文本编辑、Echarts图形化分析)
前端·网络·spring boot·网络协议·echarts
zzzll11112 天前
Spring Boot 入门指南:从零开始构建 Java Web 应用
java·前端·spring boot