当前位置:网站首页>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
边栏推荐
- The statistics of leetcode simple question is the public string that has appeared once
- Hcip day 16
- The new content of the text component can be added through the tag_ Config set foreground and background colors
- 我对新中台模型的一些经验思考总结
- 第一讲:蛇形矩阵
- [Chongqing Guangdong education] National Open University autumn 2018 0088-21t Insurance Introduction reference questions
- Metaverse Ape获Negentropy Capital种子轮融资350万美元
- Win11运行cmd提示“请求的操作需要提升”的解决方法
- Leetcode simple question: the minimum cost of buying candy at a discount
- Talking about MySQL index
猜你喜欢
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
The countdown to the launch of metaverse ape is hot
[error record] file search strategy in groovy project (src/main/groovy/script.groovy needs to be used in the main function | groovy script directly uses the relative path of code)
MySQL服务莫名宕机的解决方案
TCC of distributed solutions
科技云报道:算力网络,还需跨越几道坎?
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
航海日答题小程序之航海知识竞赛初赛
Sparse array [matrix]
Three "factions" in the metauniverse
随机推荐
Shelved in TortoiseSVN- Shelve in TortoiseSVN?
2022软件测试工程师涨薪攻略,3年如何达到30K
70. Climbing Stairs. Sol
Usage Summary of scriptable object in unity
[groovy] mop meta object protocol and meta programming (Introduction to groovyobject interface | introduction to metaclass | implementation of class methods using groovyobject invokemethod)
Kubernetes Administrator certification (CKA) exam notes (IV)
等到产业互联网时代真正发展成熟,我们将会看待一系列的新产业巨头的出现
Overriding equals() & hashCode() in sub classes … considering super fields
Some tutorials install the database on ubantu so as not to occupy computer memory?
Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
Metaverse Ape上线倒计时,推荐活动火爆进行
Go language learning tutorial (XV)
二叉树(二)——堆的代码实现
航海日答题小程序之航海知识竞赛初赛
Cobaltstrike builds an intranet tunnel
[error record] file search strategy in groovy project (src/main/groovy/script.groovy needs to be used in the main function | groovy script directly uses the relative path of code)
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
EasyCVR集群部署如何解决项目中的海量视频接入与大并发需求?
Stored procedures and stored functions
从 1.5 开始搭建一个微服务框架——日志追踪 traceId