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

}

}

相关推荐
一 乐4 小时前
家政服务管理系统|基于springboot + vue家政服务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·家政服务管理系统
老马聊技术8 小时前
AI对话功能之SpringBoot整合Vue3
vue.js·人工智能·spring boot·后端
码不停蹄的玄黓9 小时前
SpringBoot 全局异常处理器实现
java·spring boot·后端
可乐ea11 小时前
【Spring Boot + MyBatis|第7篇】JWT 登录认证与拦截器实现
java·spring boot·后端·mybatis·状态模式
我登哥MVP12 小时前
SpringCloud Alibaba 核心组件解析:服务注册与发现(Nacos)
java·spring boot·后端·spring·spring cloud·java-ee·maven
布朗克16813 小时前
39 Spring Boot Web实战
前端·spring boot·后端·实战
一 乐13 小时前
幼儿园管理系统|基于springboot + vue幼儿园管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·幼儿园管理系统
布朗克16813 小时前
38 Spring Boot入门——自动配置、核心注解与Starter机制
java·spring boot·后端
半夜燃烧的香烟13 小时前
springboot3.0 集成minio上传文件,支持多个桶名
java·开发语言·spring boot
m0_5477229214 小时前
从零搭建乒乓球比赛管理系统——Spring Boot + 原生 HTML 实战
spring boot·后端·html