当前位置:网站首页>First, redis summarizes the installation types
First, redis summarizes the installation types
2022-07-05 22:34:00 【Haozhan】
Why use Redis?
database disk IO Too slow ( The reason needs to understand the disk , Magnetic track , A sector , operating system ) Memory level databases are also too expensive , The compromise is caching
The difference between relational database and non relational database :
A relational database is a database created according to a relational model , There is a connection between data , There is no connection between non relational database data
Non relational model : Column model (Hbase), Key to model (redis,MemcacheDB), Document class model (mongoDB)
memcached and Redis The difference between
memcached and Redis Are key value pair models , however memcached There is no concept of type .
and redis There is , There are corresponding methods
therefore , be relative to memcached Come on redis It's computing that moves to data
Redis How to store data
Any data type Redis Will not directly store it in memory , Instead, use it internally redisObject To store and represent all types of key-value.
type It means a value What kind of data type is the object ( If you're interested in this key Operation and type If the supported operations do not match, they will return ),encoding It's different data types in redis Internal storage .
such as :type=string Express value What is stored is a normal string , that encoding It can be raw perhaps int, The internal coding implementation of other data types is shown in the figure below
Redis install
Prepare the next blog summary
Redis The type of
String
- Character type
Operation without any beginning :
set operation ,get operation , getset operation ( be relative to get in the future set One less time io operation ), mget operation , mset operation , msetnx operation ( Atomic operation ), append operation ,strlen operation , getrange( There are forward and reverse indexes ), setrangeset If you add nx Assign values only when there is no data
add xx Only the value can be updated , If there is, it will not be updated
Use scenarios nx Realization Distributed locking - value type
incr, incrby, incrbyfloat, decr, decrby… - bitmaps
setbit, bitpos, bitcount, bitop(and, or)
8 Bit is a byte , setbit x 8 1 Of strlen It's also 1
scene : 1. Count the login days of users in the random window
2. Count the number of user logins in the random window days
hashes
Solve the problem of storing objects , value Save key value pairs in
hget, hgetall, hincrby, hincrbyfloat, hkeys, hlen, hmget, hmset, hset, hvals
hkeys Operation query corresponding header , hvals Find out the content , hgetall Find all ( Including header and content )
hincr It can support numerical calculation of content , Can support likes , Collection and other data calculation
lists
Linked list , redis Medium key There's also a point in it list The head and tail of the pointer .
L: List perhaps Left
R: Right
B: Block Blocking
command :
- lpush, rpush Push data on the left and right
- lpop( Pop up from the right ), rpop
lpush and lpop Push and pop in the same direction is the stack
lpush and rpop Reverse push and pop is the queue
- lrange, lindex, lset, It's like an array
- lrem, linsert, ltrim
- blpop, brpop Blocking , Unicast queue
sets
duplicate removal , Do not maintain sorting ( disorder ),
Method :
- sadd( Additive elements , Automatic weight removal ), srem( remove )
- sdiff, sdiffstore, sunion, sunionstore, sinter, sinterstore (inter intersection , union Combine , diff Difference set ( There is a direction ), store Is to return a sets Types of goals )
- sismember, smembers Query how many elements
- srandmember Random events , spop It is also taken out randomly
example : Followed by a positive number Extract a non repeating result set ( It cannot be larger than the existing )
Followed by a negative number Take out a result set with duplicates ( Meet the quantity )
solve : Luck draw Positive numbers : Once you hit it, you can't hit it again
negative : If you win, you can still win ( The prize is larger than the number of people )
sorted sets
Z The first is sorted sets
stay sorted And then there will be sorted sets What is it for? ?
Functions to sort
The problem is coming. , According to what rules do you sort your deposits ?
Each deposit sorted sets Elements contain information, as well as scores and positive and negative indexes .
Method :
- zadd
- zincrby
- zcount( How many elements are there in the score range )
- zrange( View elements by ranking The score goes from small to large )[ Method can be followed by withscores Look at the score by the way ], zrangebyscore( Look at the elements in the score in positive order ), zrevrangebyscore( Look in reverse order )
- zrank View rankings
- zunion[store]… Need to give The weight weights, and aggregate Aggregation parameters ( Default : The weight * Sum the scores , also max Taking the maximum )
Underlying data structure , Yes? Implement sorting ? How fast ?
data structure : skip list Jump watch ( Sacrifice some storage space for speed )
It's about concepts : The layer number (0 Layer is the original data ), Random layering when inserting elements , Adding and deleting also need to modify the pointer , Change = Delete + increase
redis It's binary safe ( Only byte streams are transmitted ), So we must communicate the coding of the client .
Other types include
hyperloglogs、 Geographical space ( geospatial)、 news (Streams)
There are other operations :
flushall
,flushdb
,keys *
,type
,object encoding xx
,
redis Default 16 Districts Can pass select Area number selection
Redis A single thread Single process
How to handle concurrent requests ?
linux Provided by the system kernel epoll This method ( Who has data processing who )
The history of the kernel
BIO period
The system kernel provides read Method , It's blocked
problem : Multiple requests , If one of the requests is blocked , You can only process multiple requests by throwing more threads , cpu Resources will be wasted , Memory will also be wasted
Look at the system kernel method :
man 2 Method name
Query file descriptor
cd /proc/ Process number /fd
What about the process number
ps -fe [| grep Search name ]
NIO period ( Synchronous nonblocking Multiplexing epoll)
Don't block , One thread can handle , But polling occurs ( In user space )
- Synchronous non blocking period
Dead cycle monitoring
problem : Frequent switching between user mode and kernel mode , CPU Protect the site and restore the site , Too many polling calls
Solve this problem : Kernel development -> select - Still : Synchronous nonblocking
Kernel system call select Method Multiplexing
Kernel monitoring There is data kernel readjustment read Method Reduce the switching between kernel mode and user mode
problem : You still need to switch between kernel and user mode and return what can be called read
Solve this problem : Kernel redevelopment epoll(epoll_create, epoll_ctl, epoll_wait Three system calls ) and mmap( User mode and kernel mode Spaces ) -> So you don't have to copy data often - The data structure stored in the shared space is : Red and black trees and Linked list
false AIO period
detailed Redis and I/O Multiplexed blog recommendations :
https://blog.csdn.net/HD243608836/article/details/102849388
AIO Windows Can achieve AIO
0 Copy sendfile Method
nginx Multiplexing is also used epoll
边栏推荐
- Practice: fabric user certificate revocation operation process
- 点到直线的距离直线的交点及夹角
- boundary IoU 的计算方式
- Post-90s tester: "after joining Ali, this time, I decided not to change jobs."
- Kubernetes Administrator certification (CKA) exam notes (IV)
- Metaverse ape ape community was invited to attend the 2022 Guangdong Hong Kong Macao Great Bay metauniverse and Web3.0 theme summit to share the evolution of ape community civilization from technology
- [agc009e] eternal average - conclusion, DP
- Alternating merging strings of leetcode simple questions
- [groovy] mop meta object protocol and meta programming (execute groovy methods through metamethod invoke)
- The new content of the text component can be added through the tag_ Config set foreground and background colors
猜你喜欢
All expansion and collapse of a-tree
boundary IoU 的计算方式
Navigation day answer applet: preliminary competition of navigation knowledge competition
My experience and summary of the new Zhongtai model
Kubernetes Administrator certification (CKA) exam notes (IV)
Promql demo service
Oracle advanced query
[untitled]
Exponential weighted average and its deviation elimination
数据泄露怎么办?'华生·K'7招消灭安全威胁
随机推荐
Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
Postman核心功能解析-参数化和测试报告
Distributed solution selection
Technology cloud report won the special contribution award for the 10th anniversary of 2013-2022 of the "cloud Ding Award" of the global cloud computing conference
Exponential weighted average and its deviation elimination
Promql demo service
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
Google Maps case
第一讲:蛇形矩阵
My experience and summary of the new Zhongtai model
鏈錶之雙指針(快慢指針,先後指針,首尾指針)
Platformio create libopencm3 + FreeRTOS project
QT creator 7-cmake update
2022-07-05: given an array, you want to query the maximum value in any range at any time. If it is only established according to the initial array and has not been modified in the future, the RMQ meth
Some tutorials install the database on ubantu so as not to occupy computer memory?
Leetcode simple question: the minimum cost of buying candy at a discount
[agc009e] eternal average - conclusion, DP
如何快速体验OneOS
50. Pow(x, n). O(logN) Sol
BFC block level formatting context