当前位置:网站首页>Redis learning
Redis learning
2022-08-01 08:15:00 【Joy's sister is a rookie】
Redis的引入
As the amount of network requests increases,There are various pressures on the server
解决CPU及内存压力
解决IO压力
The problem with distributed clusters is
When a client requests multiple times,It is possible that each request is assigned to a different server
But every time you need to verify that the client is logged in
So we can choose tosessionIDand its value is stored as key-valuestored in the database(The database records the contents on the hard disk)中
However, the original database query is a very slow process that needs to be optimized
于是我们引入Redis
NoSQL数据库
NoSQL数据库
NoSQL(NoSQL = Not Only SQL ),意即“不仅仅是SQL”,泛指非关系型的数据库
NoSQL 不依赖业务逻辑方式存储,而以简单的key-value模式存储.因此大大的增加了数据库的扩展能力.
不遵循SQL标准.
不支持ACID.
远超于SQL的性能.
NoSQL适用场景
对数据高并发的读写
海量数据的读写
对数据高可扩展性的
NoSQL不适用场景
需要事务支持
基于sql的结构化查询存储,处理复杂的关系,需要即席查询.
(用不着sql的和用了sql也不行的情况,请考虑用NoSql)
Redis
Remote Dictionary ServerRemote dictionary system
Single-threaded memory levelNoSQL缓存数据库
非常之快(内存比硬盘快)
概述
Redis是一个开源的key-value存储系统.
和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型).
这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的.
在此基础上,Redis支持各种不同方式的排序.
与memcached一样,为了保证效率,数据都是缓存在内存中.
区别的是Redis会周期性的把更新的Data is written to disk orWrite the modification operation to the appended log file.
并且在此基础上实现了master-slave(主从)同步.
应用场景
配合关系型数据库做高速缓存
高频次,热门访问的数据,降低数据库IO
分布式架构,做session共享
多样的数据结构存储持久化数据
数据类型
(Supplement after further study)
- string
- list
- set
- hash
- Zset(带权set)
实例演示
Used by different serversredis实现session同步(spring-session-redis)
未使用Redis
开启两个项目,controller层测试代码如下:
@RequestMapping("/test.do")
@ResponseBody
public ResultObject test(HttpSession session){
if (session.getAttribute("test")!=null){
System.out.println("exam server"+session.getAttribute("test"));
}else {
System.out.println("没有session");
session.setAttribute("test","this is exam server");
}
return ResultObject.ERROR("数据失败");
}
@RequestMapping("/test.do")
@ResponseBody
public ResultObject test(HttpSession session){
if (session.getAttribute("test")!=null){
System.out.println("springboot server"+session.getAttribute("test"));
}else {
System.out.println("没有session");
session.setAttribute("test","this is springboot server");
}
return ResultObject.ERROR("数据失败");
}
开启Nginx(任务管理器中会有两个nginx.exe)
启动两个项目(Remember to change the port number of one of them)
Enter the address map of the method in the project in the address bar
(NginxSee related principles and operationsNginx相关内容)
没有导入redis,When starting two projects,他们的sessionwill be switched,So the console will prompt no every timesession
在项目中导入Redis
That is to add two dependencies:redis和spring-session
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
在配置文件中引入
spring.session.store-type=redis
随后重新启动,And enter the mapping in the browser can be found:
examnot at firstsession,创建session后,exam保存的session可以在springboot server同步
至此,我们通过redis缓存存储session,The user's request operation is implemented on different servers
补充:Want to save the user object,就要实现序列化
If you want to deserialize it out, make sure it is in同一个包下
所以,开发过程中,Creating entity classes must be serialized,Objects cannot be stored until they are serializedredis缓存中
边栏推荐
- HoloView -- Tabular Datasets
- Shell executes SQL to send emails
- 毕业论文写作技巧
- Generate pictures based on the content of the specified area and share them with a summary
- navicat mysql 内存占用过高,被强制关闭
- 最新的Cesium和Three的整合方法(附完整代码)
- 微信小程序请求封装
- HoloView -- Tabular Datasets
- SaaS安全认证综合指南
- Case practice --- Resnet classic convolutional neural network (Mindspore)
猜你喜欢
VoLTE基础学习系列 | 什么是SIP和IMS中的Forking
SAP ABAP ALV+SMARTFORS 表分页 报表打印程序
Leicester Weekly 304 6135. The longest ring in the picture Inward base ring tree
Self-made a remote control software - VeryControl
USB 协议 (二) 术语
企业数据虚拟化综合指南
网络基础学习
nodetype中值1、2、3分别代表什么意思
Leetcode - 6135: the longest part of the figure
力扣周赛304 6135. 图中的最长环 内向基环树
随机推荐
GBase 8s 锁分类
企业数据虚拟化综合指南
微信小程序请求封装
获取页面数据的方法
Do I need to introduce any dependencies to write data to clickhouse using flinksql?
22 Niu Ke Duo School 1 I. Chiitoitsu (Probability dp)
LeetCode 415:字符串相加
Mysql database deployment and initialization steps
将aof文件转换为命令waoffle安装和使用
VSCode 快捷键及通用插件推荐
热修复技术可谓是百花齐放
Golang: go to connect and use mysql
What do the values 1, 2, and 3 in nodetype mean?
特殊的日子,值得纪念
Monitor the width and height of the parent element, adapt to the size of the plug-in
国内外最顶级的8大plm项目管理系统
HoloView--Customization
VSCode插件推荐(Rust环境)
pytest接口自动化测试框架 | 执行失败跳转pdb
2022.7.31-----leetcode.1161