当前位置:网站首页>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
边栏推荐
- Solutions for unexplained downtime of MySQL services
- 等到产业互联网时代真正发展成熟,我们将会看待一系列的新产业巨头的出现
- Distance from point to line intersection and included angle of line
- How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
- thinkphp5.1跨域问题解决
- 344. Reverse String. Sol
- Opencv judgment points are inside and outside the polygon
- CA certificate trampled pit
- FBO and RBO disappeared in webgpu
- The simple problem of leetcode is to split a string into several groups of length K
猜你喜欢

MySQL服务莫名宕机的解决方案

A trip to Suzhou during the Dragon Boat Festival holiday

Postman核心功能解析-参数化和测试报告

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

Post-90s tester: "after joining Ali, this time, I decided not to change jobs."

2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*

Exponential weighted average and its deviation elimination

南京:全面启用商品房买卖电子合同

Stored procedures and stored functions

Leetcode simple question: check whether each row and column contain all integers
随机推荐
Solve the problem of "no input file specified" when ThinkPHP starts
All expansion and collapse of a-tree
What about data leakage? " Watson k'7 moves to eliminate security threats
2022软件测试工程师涨薪攻略,3年如何达到30K
Stored procedures and stored functions
Leetcode simple question: the minimum cost of buying candy at a discount
Win11 runs CMD to prompt the solution of "the requested operation needs to be promoted"
Common interview questions of redis factory
How to create a thread
Comment développer un plug - in d'applet
70. Climbing Stairs. Sol
链表之双指针(快慢指针,先后指针,首尾指针)
[groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
Leetcode simple question: check whether each row and column contain all integers
Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
119. Pascal‘s Triangle II. Sol
TCC of distributed solutions
GWT module may need to be (RE) compiled reduce - GWT module may need to be (RE) compiled reduce
Text组件新增内容通过tag_config设置前景色、背景色