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

}

}

相关推荐
只能是遇见17 分钟前
SpringBoot + vue 管理系统
vue.js·spring boot·后端
Jinkxs23 分钟前
Java 部署:Jenkins Pipeline 构建 Java 项目(自动化)
java·spring boot
a8a30227 分钟前
Spring Boot 3.3.4 升级导致 Logback 之前回滚策略配置不兼容问题解决
java·spring boot·logback
aq55356001 小时前
SpringBoot有几种获取Request对象的方法
java·spring boot·后端
steel80882 小时前
Spring Boot 整合 log4j2 日志配置教程
spring boot·单元测试·log4j
lierenvip2 小时前
Spring Boot中Tomcat配置
spring boot·tomcat·firefox
Detachym2 小时前
InsightFlow 服务配置优化与部署实践
java·spring boot·tomcat·maven·状态模式·jar
rainchestnut2 小时前
Spring AI 初步集成(1)-初始化
spring boot
流水武qin2 小时前
SpringAI多模态的基本使用
java·spring boot·spring·ai
小飞Coding2 小时前
Spring 容器生命周期:10大核心扩展接口+实战代码
spring boot