当前位置:网站首页>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缓存中
边栏推荐
- JVM: Runtime Data Area - PC Register (Program Counter)
- 正则表达式符号
- Upgrade to heavyweight lock, lock reentrancy will lead to lock release?
- sqlserver 对比两张表的差异
- navicat mysql 内存占用过高,被强制关闭
- pytest接口自动化测试框架 | 单个/多个参数
- Custom IP used in PCIE
- HoloView -- Tabular Datasets
- 22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)
- leetcode-6135:图中的最长环
猜你喜欢
【MySQL】操作表DML相关语句
Upgrade to heavyweight lock, lock reentrancy will lead to lock release?
[Beyond programming] When the fig leaf is lifted, when people begin to accept everything
leetcode-6134: Find the closest node to the given two nodes
七夕来袭——属于程序员的浪漫
类似 MS Project 的项目管理工具有哪些
Golang: go get url and form attribute value
Self-made a remote control software - VeryControl
LabVIEW中局部变量和全局变量的分配
22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)
随机推荐
MySQL查询进阶——从函数到表连接的使用你还记得吗
[Beyond programming] When the fig leaf is lifted, when people begin to accept everything
VoLTE Basic Learning Series | Enterprise Voice Network Brief
pytest接口自动化测试框架 | 使用函数返回值的形式传入参数值
数据分析6
372. 超级次方
Do I need to introduce any dependencies to write data to clickhouse using flinksql?
最小生成树
案例实践 --- Resnet经典卷积神经网络(Mindspore)
静态Pod、Pod创建流程、容器资源限制
leetcode-6132:使数组中所有元素都等于零
Go supports OOP: use struct instead of class
Holoview--Introduction
Pod环境变量和initContainer
Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
navicat mysql 内存占用过高,被强制关闭
XX市消防救援指挥中心实战指挥平台多链路聚合解决方案实例
Gethostbyname \ getaddrinfo DNS domain name IP address is not safe
pytest interface automation testing framework | single/multiple parameters
HoloView 在 jyputer lab/notebook 不显示总结