在项目中常常会用到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的更多相关文章

  1. springboot整合redis缓存

    使用springBoot添加redis缓存需要在POM文件里引入 org.springframework.bootspring-boot-starter-cacheorg.springframewor ...

  2. 在SpringBoot中添加Redis

    前言 在实际的开发中,会有这样的场景.有一个微服务需要提供一个查询的服务,但是需要查询的数据库表的数据量十分庞大,查询所需要的时间很长. 此时就可以考虑在项目中加入缓存. 引入依赖 在maven项目中 ...

  3. springboot+shiro+redis(单机redis版)整合教程-续(添加动态角色权限控制)

    相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3. springboot+shiro+redis(集群re ...

  4. springBoot集成Redis,RedisTmple操作redis和注解实现添加和清空缓存功能

    配置 maven项目进入相关配置 <dependency>    <groupId>org.springframework.boot</groupId>    &l ...

  5. SpringBoot整合Redis、ApachSolr和SpringSession

    SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...

  6. springboot集成redis(mybatis、分布式session)

    安装Redis请参考:<CentOS快速安装Redis> 一.springboot集成redis并实现DB与缓存同步 1.添加redis及数据库相关依赖(pom.xml) <depe ...

  7. springboot 使用 redis

    springboot 自己是实现了一套 redis 缓存框架, 地址: https://www.cnblogs.com/huanggy/p/9473822.html, 通过配置即可轻松愉快地实现 某些 ...

  8. springboot整合redis(简单整理)

    Redis安装与开启 我这里是在windows上练习,所以这里的安装是指在windows上的安装,操作非常简单,点击https://github.com/MicrosoftArchive/redis/ ...

  9. Spring-Boot之Redis基础

    Spring-Boot之Redis基础 准备 Redis下载地址:github.com/MSOpenTech/redis/releases Redis数据库的默认端口号是 6379 开启Redis服务 ...

  10. SpringBoot使用redis缓存List<Object>

    一.概述 最近在做性能优化,之前有一个业务是这样实现的: 1.温度报警后第三方通讯管理机直接把报警信息保存到数据库 2.我们在数据库中添加触发器,(BEFORE INSERT)根据这条报警信息处理业务 ...

随机推荐

  1. vue3学习第一天

    第一章 Options API与Composition API 重写双向绑定 vue2 基于Object.defineProperty()实现 vue3 基于Proxy proxy与Object.de ...

  2. [编程基础] C++多线程入门4-数据共享和资源竞争

    原始C++标准仅支持单线程编程.新的C++标准(称为C++11或C++0x)于2011年发布.在C++11中,引入了新的线程库.因此运行本文程序需要C++至少符合C++ 11标准. 4 数据共享和资源 ...

  3. mysql基础命令语法

    删除空格 update 表名 set 字段名 = replace(字段名 ,' ','') ; 临时表创建与删除 -- 创建临时表 create temporary table if not exis ...

  4. Ant Design Table 如何动态自定义?Ant Popover 遮挡?

    项目场景: 基于electron + Vue + node.js + express + mysql + evanpatchouli-mysql + Ant-Design-Vue,编写一款属于自己的轻 ...

  5. (数据科学学习手札149)用matplotlib轻松绘制漂亮的表格

    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 大家好我是费老师,matplotlib作为数据可 ...

  6. FAQ 关于allure和pycharm的运行模式

    关于allure和pycharm的运行模式 案例 新建一个项目allure_mode 新建一个python代码test_allure_001.py 代码如下 import pytest, os def ...

  7. 线程基础知识15-StampedLock

    1 简介 StampedLock是JDK1.8中新增的一个读写锁,也是对JDK1.5中的读写锁ReentrantReadWriteLock的优化.在原先读写锁的基础上新增了一种叫乐观读(Optimis ...

  8. kali linux 使用教程

    kali linux使用教程 前言:Kali Linux 是专门用于渗透测试的linux操作系统,它由BackTrack发展而来,在整合了IWHAX.WHOPPIX和Auditor这三种渗透测试专用L ...

  9. 使用idea的maven项目使用mybatis时遇到的坑

    在使用idea的maven项目中使用mybatis时遇到的一个问题,这个问题困扰了我一段时间,所以我来这里记录一下! 出现的问题是: 我把相同的代码复制到eclipse中,在eclipse中却能正常运 ...

  10. bat脚本登陆ftp服务器

    用bat脚本登录ftp服务器,下载指定文件. 第一次脚本,有问题,你发现了么? 由于每个">>"重定向符号之前都习惯用空格(python style),导致写道ftp. ...