1.Redis安装 for Windows

https://github.com/microsoftarchive/redis/releases

下载完成后双击安装,一直下一步

然后打开Redis安装目录打开这两个exe文件

127.0.0.1:6379> config set requirepass 123456       ## 设置密码
OK
127.0.0.1:6379> AUTH 123456
OK
127.0.0.1:6379> set mm 123
OK
127.0.0.1:6379> get mm
"123"
127.0.0.1:6379>

2.SpringBoot整合Redis

pom.xml

<!--springboot中的redis依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

yaml

spring:redis:host: 127.0.0.1port: 6379password: 123456

redisconfig


import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {RedisTemplate<String, Object> template = new RedisTemplate<>();// 配置连接工厂template.setConnectionFactory(factory);//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);ObjectMapper om = new ObjectMapper();// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和publicom.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jacksonSeial.setObjectMapper(om);// 值采用json序列化template.setValueSerializer(jacksonSeial);//使用StringRedisSerializer来序列化和反序列化redis的key值template.setKeySerializer(new StringRedisSerializer());// 设置hash key 和value序列化模式template.setHashKeySerializer(new StringRedisSerializer());template.setHashValueSerializer(jacksonSeial);template.afterPropertiesSet();return template;}@Beanpublic HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForHash();}@Beanpublic ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForValue();}@Beanpublic ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForList();}@Beanpublic SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForSet();}@Beanpublic ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForZSet();}}

redistest

import org.apache.commons.codec.DecoderException;
import org.junit.jupiter.api.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;@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTest {@Autowiredprivate RedisTemplate<String, Object> redisTemplate;@Testvoid get() throws DecoderException {Integer mm = (Integer) redisTemplate.opsForValue().get("mm");System.out.println(mm);}
}

10分钟解决Redis安装和Springboot整合相关推荐

  1. redis命令,SpringBoot整合Redis6,主从复制,哨兵模式,集群,springCache初高级应用。

    目录 1. Docker安装Redis 2. Redis的基础 2.1 redis的key命令 2.2 reids的数据结构(6.0新增的数据结构) 1. String(字符串)类型 2. List( ...

  2. Kafka精品教学(入门,安装,Springboot整合Kafka)

    ps:本文是博主结合视频和博客学习之后,自己实验总结编写的,如果侵权请联系删除. 要学习kafka首先要了解什么是消息队列,因为Kafka 是一个分布式的基于发布 / 订阅模式的消息队列(Messag ...

  3. Redis主从复制Redis哨兵机制Springboot整合哨兵

    目录 一.Redis主从复制 full resync(全量复制) partial resync(增量复制) 二.Redis主从复制配置 三.哨兵机制原理 每个 Sentinel 都需要定期执行的任务 ...

  4. kafka 安装使用 /springboot整合kafka /消息投递机制以及存储策略 /副本处理机制

    一.背景 1.基本信息 Kafka是由Apache软件基金会开发的一个开源流处理平台,由Scala和Java编写.Kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者在网站中的所有动作流 ...

  5. Swagger的安装以及SpringBoot整合Swagger2实现SwaggerAPI文档测试

    前言 本篇博客是本人在网上学习Swagger所产出的个人笔记.主要内容有: 1.Swagger的安装 2.Swagger的介绍 3.Swagger2中常用的注解 4.快速上手案例 准备工作:Swagg ...

  6. 解决:Activiti7与SpringBoot整合时,默认生成的activiti数据库中只有17张表,无另外8张历史表

    问题 Activiti7与SpringBoot整合时,默认生成的activiti数据库中只有17张表,无另外8张历史表. 原因 Activiti默认关闭了历史表的使用. 解决 在连接数据库的appli ...

  7. redis进阶之SpringBoot整合Redis(五)

    在聊 SpringBoot整合redis之前,我们先看看 Redis推荐的java连接开发工具:jedis知其然并知其所以然,授人以渔! 学习不能急躁,慢慢来会很快! Jedis 什么是Jedis 是 ...

  8. datax安装 及 springboot整合 datax

    换了新工作,Java出身的我,弄点大数据的活. datax安装 环境要求 1.jdk1.8 2.python 源码地址:https://github.com/alibaba/DataX 这里我下载的是 ...

  9. 10分钟解决一天工作量它不香吗?没有想到你们竟这么想…

    问:从每天工作8小时,进化成每天工作10分钟.中间差几步? 答:一步,Python自动化办公! "Python是挺好的,但我不是程序员,也不想转行当程序员,还学习Python干嘛?学Pyth ...

最新文章

  1. kepserver 三菱fx_#电工培训# #plc培训# PLC培训 学在智通 赢在职场【三菱plc吧】
  2. JAVA 邮件发送工具类
  3. controller层没反应_埋地管道防腐层探测检漏仪FJ-10地下管线探测仪的说明及应用...
  4. 关于MySQL出现锁等待lock wait timeout exceeded; try restarting transaction 的解决方案
  5. WinJS实用开发技巧(4):Appbar中使用自定义图片
  6. 大爷与支付宝同名,曾想状告阿里巴巴侵权,现在过得怎么样
  7. 大数据之-Hadoop3.x_MapReduce_ReduceJoin案例Mapper---大数据之hadoop3.x工作笔记0130
  8. 并行DA实验c语言程序,求助怎么把两个单片机c语言程序结合在一起?大一期末实验...
  9. [javaSE] 集合框架(迭代器)
  10. C++ std::vector 一维 二维数组 初始化 为0
  11. 接口文档模板(Markdown)
  12. 数据库学生管理系统课程设计
  13. 从零开始入门芯片行业
  14. [转]51汇编指令集详解()
  15. 计算机内存占用过高,内存,教您电脑内存占用高怎么办
  16. 有一群志同道合的程序员朋友是怎样的体验?
  17. WebRTC禁用NACK
  18. HackTheBox 如何使用
  19. windows 10---MySQL 8.0的安装教程
  20. java的clone你知道多少?

热门文章

  1. asp.net 安装element ui_Vue+Element环境搭建
  2. 滚动到底部自动加载 html,移动端页面滚动到底部自动加载数据
  3. c语言运行后出现xt073,2017年北京工业大学城市交通学院894C语言与数据结构之C程序设计考研强化模拟题...
  4. python将字符串拆分成单词_将字符串拆分为单词和标点符号
  5. UE4 性能优化方法(工具篇)
  6. Cryengine 3新的全局光照算法简介
  7. UE3 后期处理编辑器用户指南
  8. Kotlin开发细节
  9. 全面支持3.0 新华三“力夯”可信计算发展
  10. 支付宝小程序公测!教程新鲜出炉