当前位置:网站首页>Redis - learn five types of NoSQL
Redis - learn five types of NoSQL
2022-06-11 16:40:00 【All eyes are on it】
One , What is? NoSQL
NoSQL
NoSQL = Not Only SQL ( not only SQL)
Relational database : form , That's ok , Column
Non relational database in general , With web 2.0 The birth of the Internet ! Traditional relational databases are hard to deal with web 2.0 Time !
Especially large scale and high concurrency community ! A lot of insurmountable problems have been exposed ,NoSQL In today's big data environment, it is developing very rapidly ,Redis It's the fastest growing , And it's a technology that we have to master right now !
Many data types User's personal information , Social networks , Location . The storage of these data types does not require a fixed format ! It can be expanded horizontally without many months of operation !Map<String,Object> Use key value pairs to control !
NoSQL characteristic
decoupling !
1, Easy to expand ( There's no relationship between the data , Good extension !)
2, Maximum performance of big data (Redis Write in a second 8 Ten thousand times , Read 11 ten thousand ,NoSQL Cache record level of , It's a fine-grained cache , The performance will be relatively high !)
3, Data types are diverse !( There's no need to design the database in advance ! Take it and use it ! If it's a table with a lot of data , A lot of people can't design !)
4, Tradition RDBMS and NoSQL
Conventional RDBMS database
- Structured organization
- SQL
- Data and relationships exist in separate tables
- Operation operation , Data definition language
- Strict consistency
- Basic business
- .......
NoSQL
- It's not just data
- There is no fixed query language
- Key value pair storage , Column store , Document storage , Graphic database ( social connections )
- Final consistency
- CAP Theorem and BASE ( Different live ) Junior Architect !
- High performance , High availability , Highly expandable
- .........
understand :3V+3 high ??? distributed file system FastDFS
Two ,NoSQL The four major categories of
1, Key value pair storage 2, Column store 3, Document storage 4, Graphic database
KV Key value pair :
- Sina :Redis
- Meituan :Redis + Tair
- Ali , Baidu :Redis + memecache
Document database (bson Format and json equally ):
- MongoDB( Generally, we must master )
- .MongoDB Is a database based on distributed file storage ,C++ To write , It is mainly used to process a large number of documents !
- .MongoDB It's a gap between Intermediate products between relational databases and non relational data !MongoDB Yes no relational database has the most functions , Most like a relational database !
- ConthDB
Column store database :
- HBase
- distributed file system
Graph relational database :

- He doesn't store graphics , It's about relationships , such as : Circle of friends social network , Advertising recommendation !
- Neo4j , lnfoGrid;
Understand non relational databases

3、 ... and ,Redis introduction
Concept
Redis What is it? ?
Redis (Remote Dictionary Server), Remote dictionary service !
It's an open Use of source ANSI C Language writing , Support network , Log type that can be memory based or persistent ,Key-Value database , And provide multilingual API.
Redis Periodically, updated data is written to disk or changes are written to an appended log file , And on this basis to achieve master-slave( Master-slave ) Sync .
Free and open source ! It's the hottest thing right now NoSQL One of the technologies ! Also known as structured database !
Redis What can I do? ?
1, Memory storage , Persistence , In memory, power is lost , So persistence is important (rdb,aof)
2, Efficient , Can be used for caching
3, Publish subscribe system
4, Map information analysis
5, timer , Counter ( Browse volume !)
characteristic :
1, A variety of data types 2, Persistence 3, colony 4, Business .....
Be careful :Wdinow stay Github Upload and download ( It's been a long time !)
==Redis The recommendations are all in Linux Built on the server , We are based on Linux Study !==
Test link
Window operation


Remember a word ,Window It's really easy to use , however Redis It is recommended that we use Linux To develop and use !
The use of foundations
Redis The default is 16 A database
Redis It's single threaded !
understand Redis It's very fast , Official expression ,Redis It's based on memory operations ,CPU No Redis Performance bottleneck ,Redis The bottleneck is based on the memory and network bandwidth of the machine , Now that you can use a single path to implement , Single thread is used ! All use single thread !
Redis Why is single thread so fast ?
The core :redis Is to put all the data in memory , So using single thread to operate is the highest efficiency , Multithreading (CPU The context switches : Time consuming operations !!!), For memory systems , If context switching is not used, it is the highest ! Read and write many times in the same CPU Upper , In the case of memory , This is the best solution !
Redis Five data types :
Redis -key
keys * # View all key
set name liu # set key
EXISTS name # Judge the current key Whether there is
move name 1 # Remove current key
EXPIRE name 10 # Set up key The expiration time of , The unit is seconds
ttl name # View expiration time
type name # View the current key A type of
String ( character string )
set key1 v1 # Set the value
get key # Get value
keys * # Get all key
EXISTS key1 # Judge a certain key Whether there is
APPEND key "hello" # Append string , If at present key non-existent , Equivalent to setkey
STRLEN key1 # Gets the length of the string
i++ operation
set views 0 # Initial views are 0
incr views # Self increasing 1
decr views # Self reduction 1
INCRBY views 10 # Set the self increment quantity
String range renge
set key 1"liu" # Set up key1 Value
GETRANGE key1 0 3 # Intercepting string 【0,3】
GETRANGE key1 0 -1 # Get all the strings
Replace 、
SETRANGE key2 1 xx # Replace the string starting at the specified position !
setex (set with expire) # Set expiration time
setnx (set not exist) # non-existent Set up
mset k1 k2 k3 k4 # Set multiple values at the same time
mget k1 k2 k3 # Get multiple values at the same time
msetnx k1 k2 k3 # msetnx It's an atomic operation , Or make it together , Or fail together !
String Similar usage scenarios :value In addition to our characters, it can also be our numbers !
- Counter
- Count the number of multiple units uid:1 yes id
- Number of fans
- Object cache storage !
List :( data type )
Basic data types , list

stay Redis Inside , We can List Play into , Stack , queue , Blocking queues !
be-all List The orders are based on L At the beginning
LPUSH list xxx # Put one or more values , Insert to the head of the list
LRANGE list 0 -1 # obtain list The median ! You can also distinguish between fetched values
RPUSH list righr # Set one or more values , Insert into the list bit section ( Right )
LPOP list # remove list The first element of
RPOP list # remove list Last element of
Lindex list 1 # Get the first value of off-duty
Lpush list xxx # add value
Lrem list 1 xxx # remove This 1 Is to remove several Can be repeated
Ltrim mylist 12 # Intercept the specified length by subscript , This list Has been changed , Truncated. Only the intercepted elements are left !
Set ( aggregate )
set The value in cannot be reread
sadd myset "hello" # set Add... To the collection
SMEMBERS myset # View specified set All values
SISMEMBER myset hello # Determine whether a value is in set Collection
scard myset # obtain set The number of content elements in the collection !
srem myset hello # remove set The specified element in the collection
SRANDMEMBER myset # Randomly select an element
spop myset # Delete some at random set The elements in the collection !

Hash( Hash )
Map aggregate ,key -<key-vlaue> When this value is a map aggregate ! The nature and String There's no big difference in type , It's still a simple key-vlaue!
hset myhash field1 liu #set A specific key -vlaue
hget myhash field1 # Get a field value
hmset myhash field1 hello field2 world # Get multiple field values
hgetall myhash # Get all the data
hdel myhash field # Delete hash Appoint key Field ! Corresponding vlaue The value disappears !
hlen myhash # obtain myhash The number of fields in the table
HEXISTS myhash field1 # Judge hash Specifies whether the field exists !
hkeys myhash # Just get all field
hvals myhash # Just get all value
Zset( Ordered set )
zadd myset 1 noe # Add a value
zadd myset 2 two 3 three # Add multiple values
----- How to implement sorting --------
zadd salary 2500 xiaohong # Add three users
ZRANGEBYSCORE salary -inf +inf # Show all users From small to large
ZRANGEBYSCORE salary -inf +inf withscores # Show all users with grades
ZRANGEBYSCORE salary -inf 2500 withscores # Show salary less than 2500 Descending sort of employees
zrem salary liu # Remove the specified element from the ordered collection
zcard salary # Get the number of ordered sets
边栏推荐
- Interview classic question: how to do the performance test? [Hangzhou multi surveyors] [Hangzhou multi surveyors \wang Sir]
- (OJ assignment of Hunan University of science and Technology) problem g: pattern matching of strings
- RSP: An Empirical Study of remote sensing pre training
- Text driven for creating and editing images (with source code)
- 整了20张高清数据分析全知识地图,强烈建议收藏!
- The micro service failed to connect to the cloud sentinel console and the link blank problem occurred after the connection was successful (resolved)
- Search and graph theory: Dijkstra finding the shortest path i-dijkstra (shortest path)
- Why does chip design also need "Craftsmanship"?
- 网络流媒体协议的联系与区别(RTP RTCP RTSP RTMP HLS)
- Persistence mechanism of redis
猜你喜欢

为什么芯片设计也需要「匠人精神」?

LeetCode——24. 两两交换链表中的节点(三指针)

Global and Chinese molten carbonate fuel cell industry outlook and market panoramic Research Report 2022-2028

leetcode463. Perimeter of the island (simple)

^31原型面试题

时序预测 | MATLAB实现RBF径向基神经网络时间序列未来多步预测

Differences between list and set access elements

485天,我远程办公的 21 条心得分享|社区征文

2022年R1快開門式壓力容器操作考試題庫及模擬考試

JVM 的组成
随机推荐
[sword finger offer] 21 Adjust array order so that odd numbers precede even numbers
leetcode-141. Circular linked list
VLAN partition and routing between VLANs
Global and Chinese molten carbonate fuel cell industry outlook and market panoramic Research Report 2022-2028
What is RS stamp paper?
leetcode684. 冗余连接(中等)
jsp页面初始加载方式
C# 启动一个外部exe文件,并传入参数
leetcode684. Redundant connection (medium)
solr(二)solr添加core以及依赖包路径
Oracle生成不重复字符串 sys_guid()与Mysql生成唯一值
golang中的异常处理和异常使用
Simulated 100 questions and simulated examination for main principals of hazardous chemical business units in 2022
2022 safety officer-a certificate test question simulation test question bank simulation test platform operation
2022 simulated examination question bank and simulated examination for crane driver (limited to bridge crane)
Leetcode 1974. Minimum time to type words using a special typewriter (yes, once)
[opencvsharp] spot detection barcode decoding image operation image rotation / flip / Zoom perspective transformation image display control demo notes
2022G1工业锅炉司炉考题及模拟考试
【opencvsharp】opencvsharp_ samples. Core sample code Notes
时间复杂度与空间复杂度解析