【SpringBoot】SpringBoot项目中实现数据缓存

[复制链接]
发表于 2026-2-5 19:26:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
步调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"));
}
}
 
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表