当前位置:网站首页>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缓存中
边栏推荐
- Prime Ring Problem(素数环问题)
- 力扣周赛304 6135. 图中的最长环 内向基环树
- pytest接口自动化测试框架 | parametrize中ids的用法
- leetcode-6132:使数组中所有元素都等于零
- GO error handling
- zip打包目录所有文件(含隐藏文件/夹)
- 数据分析5
- Flink SQL - client, how to deal with the source side and to increase the target, the SQL - client including mapping table and the JOB such as
- Data Analysis 5
- Shell executes SQL to send emails
猜你喜欢
leetcode-6133:分组的最大数量
leetcode-6134: Find the closest node to the given two nodes
Golang: go get url and form attribute value
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
VSCode插件推荐(Rust环境)
The log causes these pits in the thread block, you have to prevent
【编程之外】当遮羞布被掀开,当人们开始接受一切
How to get page data
LevelSequence源码分析
Data Analysis 5
随机推荐
various network protocols
navicat mysql 内存占用过高,被强制关闭
将aof文件转换为命令waoffle安装和使用
The log causes these pits in the thread block, you have to prevent
pytest interface automation testing framework | parametrize source code analysis
类似 MS Project 的项目管理工具有哪些
pytest interface automation testing framework | pass in parameter values in the form of function return values
【ASWC Arxml结构分解】-7-Explicit(显式)和Implicit(隐式) Sender-Receiver communication描述差异
Centos install php7.4, build hyperf, forward RDS
Mysql数据库的部署以及初始化步骤
leetcode-6133: maximum number of groupings
JVM内存模型之深究模型特征
数据分析6
How to get page data
Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download
HoloView--Customization
leetcode 42. 接雨水
Chapter 9 of Huawei Deep Learning Course - Convolutional Neural Network and Case Practice
pytest接口自动化测试框架 | 跳过模块
22牛客多校1 C.Grab the Seat (几何 + 暴力)