Springboot 添加redis
在项目中常常会用到redis来缓存信息,下面就是如何在Springboot中添加redis
1:在pom.xml中添加依赖
2:配置redis
3:测试使用redis
1:在pom.xml中添加依赖,为了方便测试,这里添加了测试依赖
<!--测试依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <!--redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2:在application.yml中配置redis
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/test?
useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: password #redis
redis:
host: 10.1.3.188
port: 6379
password: 123456

这里需要注意的是 在application.yml 中的格式,我这里粘贴代码,不知道为什么格式不是很对,yml对格式很严格,错了一点就都不行,这里我再粘贴一下我的图片
2:测试使用redis
package com.yyy.Redis; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner; /**
* @auther YueYangyang
* @date 2020/6/27 10:20
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTest { @Autowired
private RedisTemplate redisTemplate; @Test
public void redis(){
redisTemplate.boundValueOps("name").set("哈哈");
System.out.println( redisTemplate.boundValueOps("name").get());
} }
Springboot 添加redis的更多相关文章
- springboot整合redis缓存
使用springBoot添加redis缓存需要在POM文件里引入 org.springframework.bootspring-boot-starter-cacheorg.springframewor ...
- 在SpringBoot中添加Redis
前言 在实际的开发中,会有这样的场景.有一个微服务需要提供一个查询的服务,但是需要查询的数据库表的数据量十分庞大,查询所需要的时间很长. 此时就可以考虑在项目中加入缓存. 引入依赖 在maven项目中 ...
- springboot+shiro+redis(单机redis版)整合教程-续(添加动态角色权限控制)
相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3. springboot+shiro+redis(集群re ...
- springBoot集成Redis,RedisTmple操作redis和注解实现添加和清空缓存功能
配置 maven项目进入相关配置 <dependency> <groupId>org.springframework.boot</groupId> &l ...
- SpringBoot整合Redis、ApachSolr和SpringSession
SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...
- springboot集成redis(mybatis、分布式session)
安装Redis请参考:<CentOS快速安装Redis> 一.springboot集成redis并实现DB与缓存同步 1.添加redis及数据库相关依赖(pom.xml) <depe ...
- springboot 使用 redis
springboot 自己是实现了一套 redis 缓存框架, 地址: https://www.cnblogs.com/huanggy/p/9473822.html, 通过配置即可轻松愉快地实现 某些 ...
- springboot整合redis(简单整理)
Redis安装与开启 我这里是在windows上练习,所以这里的安装是指在windows上的安装,操作非常简单,点击https://github.com/MicrosoftArchive/redis/ ...
- Spring-Boot之Redis基础
Spring-Boot之Redis基础 准备 Redis下载地址:github.com/MSOpenTech/redis/releases Redis数据库的默认端口号是 6379 开启Redis服务 ...
- SpringBoot使用redis缓存List<Object>
一.概述 最近在做性能优化,之前有一个业务是这样实现的: 1.温度报警后第三方通讯管理机直接把报警信息保存到数据库 2.我们在数据库中添加触发器,(BEFORE INSERT)根据这条报警信息处理业务 ...
随机推荐
- 可视化—AntV G6 高亮相邻节点的两种方式
目录 内置的高亮节点 自定义高亮 自定义高亮时保持原始颜色 总结 案例完整代码 通过官方文档,可知高亮相邻节点分为两种方法,文档描述并不是很清楚,对刚接触这个库的小白并不是很友好,慢慢总结慢慢来吧 内 ...
- ubunut安装qtcreater
安装gcc 1 kxb@kxb:~$ gcc -v 2 3 Command 'gcc' not found, but can be installed with: 4 5 sudo apt insta ...
- 通过this引用成员方法-类的构造器
通过this引用成员方法 this代表当前对象,如果需要引用的方法就是当前类中的成员方法,那么可以使用"this成员方法"的格式来使用方法引用.首先是简单的函数式接口︰ 下面是一个 ...
- 聊一聊js中元素定位的方法
在做selenium web自动化的时候,有时通过selenium定位不到,或无法操作元素,这个时候就需要通过js来 定位/操作元素,然后通过selenium自带的execute_script()方法 ...
- Salesforce LWC学习(四十一) If:true 即将弃用?
本篇参考: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_dir ...
- 新版Bing 搜索后台的.NET 技术栈
微软在今天在Redmond 线下举办媒体一场活动,发布了新版的微软必应,在桌面上推出了测试版,移动版也即将推出.微软首席执行官纳德拉称Al-powered搜索为公司自云15年以来最大的事情. 2023 ...
- Cpp 友元简述
友元函数,友元类 使用友元,主要是易于直接访问数据,但友元本质是以破坏封装性为代价. 下例引用于: <C++程序设计(第2版)> 友元声明位置由程序设计者决定,且不受类中public.pr ...
- W04 散文周刊 : 重回Emacs
W04 散文周刊 : 重回Emacs 邮箱:ppbhoy@qq.com 博客地址: www.pipihao.com 公纵号:南湖小皮 公告:后面会开始稳定更新 使用Emacs还是有些沉重,我一直将Em ...
- springcloud11 spring cloud config
1.spring cloud config是什么 官网:https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.2.1.RE ...
- 【翻译】API 链接与键:为什么应该使用链接而不是键来表示 API 中的关系
翻译自原文: https://cloud.google.com/blog/products/application-development/api-design-why-you-should-use- ...