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

}

}

相关推荐
沫离痕13 小时前
Cassandra 4.0.11 Docker 安装与配置手册
java·spring boot
山东点狮信息科技有限公司14 小时前
SpringBoot+VUE3,一套系统完成OA+HRM+CRM+MES+合同+项目管理 —— 深度解析点狮全业务管理平台
java·spring boot·后端
卓怡学长15 小时前
w263基于springboot + vue 健康饮食管理系统
java·数据库·vue.js·spring boot·spring·intellij-idea
万亿少女的梦16816 小时前
基于Spring Boot、Vue.js和MySQL的超市管理系统设计与实现
java·vue.js·spring boot·mysql·管理系统
至乐活着18 小时前
Spring Boot 3.x核心特性深度解析:拥抱Java 17与云原生时代
spring boot·云原生·graalvm·java 17·虚拟线程
Y0011123618 小时前
SpringBoot 基础篇
java·spring boot·spring
weixin_BYSJ198720 小时前
springboot美食食谱小程序---附源码24044
java·spring boot·python·spring cloud·django·tomcat·php
ZhengEnCi1 天前
S02-SpringBoot实体类新增字段对已有数据的影响及自动DDL同步机制详解
数据库·spring boot