当前位置:网站首页>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
边栏推荐
- Promql demo service
- IIC bus realizes client device
- When the industrial Internet era is truly mature, we will look at the emergence of a series of new industrial giants
- 119. Pascal‘s Triangle II. Sol
- Starting from 1.5, build a micro Service Framework -- log tracking traceid
- 2022 Software Test Engineer salary increase strategy, how to reach 30K in three years
- Unique occurrence times of leetcode simple questions
- 鏈錶之雙指針(快慢指針,先後指針,首尾指針)
- 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
- Go语言学习教程(十五)
猜你喜欢

點到直線的距離直線的交點及夾角

如何快速体验OneOS

Navigation day answer applet: preliminary competition of navigation knowledge competition

点到直线的距离直线的交点及夹角

从 1.5 开始搭建一个微服务框架——日志追踪 traceId

Damn, window in ie open()

Leetcode simple question: the minimum cost of buying candy at a discount

Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题

Leetcode simple question: check whether each row and column contain all integers

Technology cloud report: how many hurdles does the computing power network need to cross?
随机推荐
分布式解决方案选型
Performance testing of software testing
Postman core function analysis - parameterization and test report
MySQL服务莫名宕机的解决方案
Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space
Go language learning tutorial (XV)
CA certificate trampled pit
我对新中台模型的一些经验思考总结
The new content of the text component can be added through the tag_ Config set foreground and background colors
二叉树(三)——堆排序优化、TOP K问题
Draw a red lantern with MATLAB
Sub total of Pico development
Shelved in TortoiseSVN- Shelve in TortoiseSVN?
My experience and summary of the new Zhongtai model
Search: Future Vision (moving sword)
谷歌地图案例
Nanjing: full use of electronic contracts for commercial housing sales
记录几个常见问题(202207)
Solutions for unexplained downtime of MySQL services
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程