当前位置:网站首页>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
边栏推荐
- 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
- 科技云报道:算力网络,还需跨越几道坎?
- [groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
- Sparse array [matrix]
- Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
- 分布式解决方案选型
- [untitled]
- Unique occurrence times of leetcode simple questions
- GWT module may need to be (RE) compiled reduce - GWT module may need to be (RE) compiled reduce
- What about data leakage? " Watson k'7 moves to eliminate security threats
猜你喜欢

实战:fabric 用户证书吊销操作流程

Pl/sql basic case

U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程

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

Exponential weighted average and its deviation elimination

Damn, window in ie open()
![[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)](/img/3e/34b45cd14f0302bb381efd244bc68f.jpg)
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)

Distributed resource management and task scheduling framework yarn

What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial

The difference between MVVM and MVC
随机推荐
记录几个常见问题(202207)
boundary IoU 的计算方式
What changes has Web3 brought to the Internet?
Binary tree (III) -- heap sort optimization, top k problem
Metaverse Ape获Negentropy Capital种子轮融资350万美元
Leetcode simple question: check whether each row and column contain all integers
The statistics of leetcode simple question is the public string that has appeared once
ESP32 hosted
Leetcode simple question check whether all characters appear the same number of times
科技云报道:算力网络,还需跨越几道坎?
Alternating merging strings of leetcode simple questions
点到直线的距离直线的交点及夹角
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
如何快速体验OneOS
Oracle advanced query
第一讲:蛇形矩阵
Opencv judgment points are inside and outside the polygon
Matlab draws a cute fat doll
How to reverse a string fromCharCode? - How to reverse String. fromCharCode?
Damn, window in ie open()