Redis入门整合springboot
快速使用
首先到cmd里面去打开这个redis服务
卸载服务:redis-server --service-uninstall
安装服务:redis-server --service-install redis.windows.conf
开启服务:redis-server --service-start
停止服务:redis-server --service-stop
使用第三句 开启计算机服务
redis-cli.exe -h 127.0.0.1 -p 6379
首先先到f盘里面找到解压好的redis文件夹 然后使用windows终端进入 然后输入上面这一句 这句话的意思是 启动redis的服务端 是本机的 6379端口
然后就可以连接redis 和我们的计算机了
关闭服务
关闭后再去查那些数据 因为是存到的是内存里面 所以 这些数据就直接没了
高级使用
上面介绍的是redis的最最基础的入门接下来介绍的是他的高级使用
快速整合springboot
首先我们需要知道 redis的优势 是什么 快 存也快取也快 这样我们就能使用他的这个特点 将一些比较常用的 热点对象存到内存里面去 这样 我们读取的时候就能变得更加方便。 比如 我有一个商品 大家都想买 如果我放到数据库里面去 那么查询数据库有一大堆的目标是因为这个商品 那我存到内存里面去 这样他就能通过访问内存 来取了 大大减少了数据库的压力。 接下来使用一个demo来介绍怎么使用springboot来进行redis的使用
启动器<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>
package com.bsos.service.pojo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.Alias;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;import java.io.Serializable;
import java.sql.Date;/*** @author Michelle*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@Component
@Alias("product")
public class Product implements Serializable {实体类这里一定要注意实现序列化 因为如果要存到内存里面去 是将这个对象序列化
之后在传进去的 所以要让他能序列化String PR_ID;String PR_Name;Date PR_Day;int PR_Min;String PR_Mode;int PR_Style;String PR_HLight;}
package com.bsos.service.config;import com.bsos.service.pojo.Product;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.tomcat.jni.User;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurationSelector;
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.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;/*** @author Michelle*/
@Configuration
public class RedisConfig {这里是redis的配置类 这里面主要是将他自带的那个redistemple进行了重写 因为我
们使用redis传进去的大多数时候是《string,object》类型的 但是原生的redistemple是泛型
所以我们需要重新写一下 这里就写成 string+product类型的 因为我们的key和value也
需要实现序列化 所以我们使用序列化器来对他们进行序列化 因为他默认的序列化器只能
用string类型 所以我们配置一下 这样就能根据我们的需要来进行序列化。@Beanpublic RedisTemplate<String, Product>redisTemplate(RedisConnectionFactory factory){RedisTemplate<String,Product>template=new RedisTemplate<>();//关联template.setConnectionFactory(factory);//设置key的序列化器template.setKeySerializer(new StringRedisSerializer());//设置value的序列化器template.setValueSerializer(new Jackson2JsonRedisSerializer<>(Product.class));return template;}}
package com.bsos.service.mapper;import com.bsos.service.pojo.Product;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;import javax.annotation.Resource;import static org.junit.jupiter.api.Assertions.*;@SpringBootTest
class ProductMapperTest {@Autowiredprivate RedisTemplate<String,Product> redisTemplate;@AutowiredProductMapper productMapper;@Testvoid delProductById() {Product product = new Product();product.setPR_ID("123456");product.setPR_Name("test");
// redisTemplate.opsForValue().set("myProduct",product);Product myProduct = redisTemplate.opsForValue().get("myProduct");System.out.println(myProduct.toString());System.out.println(redisTemplate.opsForValue().get("myProduct"));}
这里就是试一下这个起作用了没 很明显他是查到了 而且读取出来的时候也能自动的转化为我们的原来的类型}
Redis入门整合springboot相关推荐
- Shiro 入门笔记,整合SpringBoot,Redis
Shiro 入门笔记 视频地址:https://www.bilibili.com/video/BV1uz4y197Zm 感谢编程不良人的教程 1. 权限管理 权限管理包括用户 身份认证 和 授权 两部 ...
- redis安装到熟练整合springboot(篇幅较长内容详细)
尚硅谷课程redis学习笔记 1.在linux下安装redis数据库 这篇文章介绍安装 redis介绍: Redis是一个开源的key-value存储系统. 和Memcached类似,它支持存储的va ...
- Redis主从复制Redis哨兵机制Springboot整合哨兵
目录 一.Redis主从复制 full resync(全量复制) partial resync(增量复制) 二.Redis主从复制配置 三.哨兵机制原理 每个 Sentinel 都需要定期执行的任务 ...
- redis入门——Spring整合篇
redis入门--Spring整合篇 @(Redis)[服务器, 连接池, 集群, jedis, spring] redis入门Spring整合篇 Spring整合Redis redis整合分析 编写 ...
- 10分钟解决Redis安装和Springboot整合
1.Redis安装 for Windows https://github.com/microsoftarchive/redis/releases 下载完成后双击安装,一直下一步 然后打开Redis安装 ...
- Shiro框架学习笔记、整合Springboot、redis缓存
本笔记基于B站UP主不良人编程 目录 1.权限的管理 1.1什么是权限管理 1.2什么是身份认证 1.3什么是授权 2.什么是Shiro 3.Shiro的核心架构 3.1 S核心内容 4.shiro中 ...
- Redis整合SpringBoot,出现“\xac\xed\x00\x05t\x00\x03解决自定义RedisTemplate序列化
SpringBoot整合 SpringBoot操作数据:spring-data jpa jdbc mongodb redis SpringData也是和SpringBoot齐名的项目 说明:在Spri ...
- SpringSecurity整合springBoot、redis——实现登录互踢
背景 基于我的文章--<SpringSecurity整合springBoot.redis token动态url权限校验>.要实现的功能是要实现一个用户不可以同时在两台设备上登录,有两种思路 ...
- Redis 安装配置开机启动整合SpringBoot以及配置文件详解
安装 Redis # 下载Redis wget https://download.redis.io/releases/redis-6.0.9.tar.gz# 解压 redis tar -zxvf re ...
- redis进阶之SpringBoot整合Redis(五)
在聊 SpringBoot整合redis之前,我们先看看 Redis推荐的java连接开发工具:jedis知其然并知其所以然,授人以渔! 学习不能急躁,慢慢来会很快! Jedis 什么是Jedis 是 ...
最新文章
- 运维开发笔记整理-前后端分离
- 爬虫 python 爬取php的网页,带有post参数的网页如何爬取
- 知乎高赞:本科生如何才能进入腾讯、阿里等一流互联网大厂?
- Codeforces Round #674 (Div. 3) F. Number of Subsequences 简单计数dp
- 概率整形 Peobabilistic Shaping PS 第一节
- 【clickhouse】clickhouse强大智能的 Projection (投影) 功能
- Adaboost算法结合Haar-like特征
- 【Shader入门精要】第十四章——卡通风格的渲染
- ZEMAX | 如何使用渐晕系数
- 视频编码中的PAFF和MBAFF的区别 转自:http://blog.csdn.net/kerryhung/article/details/4433256
- react-custom-scrollbars样式
- devc 和mysql_DEV C++下C语言连接mysql
- python宣传海报_用Python做一个令人发疯的海报
- 量子前沿英雄谱|既研究陶艺,也研究光量子:Hideo Mabuchi
- 2018 ACM-ICPC, Syrian Collegiate Programming Contest F. Pretests(子集dp)
- 如何通过二极管设计一个或门电路
- Django restframework 认证
- 高德地图 toolbar
- html中repeat的作用,html中hover和no-repeat
- 设计简约风格节约用水公益海报的PS教程
热门文章
- 片假名翻译软件测试,怎么写软件测试用例
- .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx)
- python凯撒密码流程图_python实现凯撒密码、凯撒加解密算法
- 内网神器cobaltstrike使用教程
- Matlab绘制曲线
- matlabadftest_adf检验matlab程序
- Malmquist指数DEAP2.1应用
- 华为hg255d+Openwrt锐捷认证在某农业公园
- 如何在虚拟机安装windows server 2003
- Qt setFocus