当前位置:网站首页>Basic introduction of redis and explanation of eight types and transactions
Basic introduction of redis and explanation of eight types and transactions
2022-07-03 05:15:00 【A wild man about to succeed】
Redis
Redis It's single threaded
Redis It's very fast , The official website said ,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 .
Redis yes C Written language , The official data is 100000+ Of QPS, It's not the same as using key-value Of Memecache Bad
Redis Why is single thread so fast ?
boring 1: High performance servers are not necessarily multithreaded
myth 2: Multithreading (CPU The context switches !), It must be more efficient than a single thread !
Go first CPU> Memory > To understand the speed of the hard disk
The core :redis Is to put all the data in memory , So using single thread to operate is the highest efficiency , Multithreading (CPU Will switch context : Time consuming operations ), For memory systems , If there is no context switch , Efficiency is the highest . Read and write many times in the same CPU Upper , In the case of memory , This is the best solution .
Redis Eight storage types
String
APPEND haha f
get haha# The value is f
List
list , Queues and stacks can be implemented
LPUSH list one# Stack insert
LPUSH list two
LPUSH list three
LRANGE list 0 -1# Get all by default list====>three,two,one
LRANGE list 0 1# obtain 0 and 1 The elements of ,three two
RPUSH list haha# Queue insertion
LRANGE list 0 -1# Get all by default list====>three,two,one,haha
Set
It's simple , Check on the official website
Hash
It's simple , Check on the official website
Zset
Ordered set , Can sort
Rank salary
Geospatial
Map
Enter the city name , Latitude and longitude , Then you can calculate the distance or people nearby
Hyperloglog
Radix sorting
PFadd mykey a b c d e f g h i j# Create the first set of elements mykey
PFCOUNT mykey# obtain 10
PFadd mykey2 i j z x c v b n m
PFCOUNT mykey2# obtain 9
PFMERGE mykey3 mykey mykey2# Combine
PFCOUNT mykey3# obtain 15
Web page UV( A person visits many times , Finally, it's one more time )
Bitmap
Bitmap (0 and 1 The status code )
setbit haha 0 1
setbit haha 1 1
setbit haha 2 0
getbit haha 2# obtain 0
bitcount haha 0 2# from key0 To key2 Get value 1
bitcount haha# Get all values by default 1
Log in , Is it active , Whether to punch in or not
It can be used bigcount Calculate how much 0 and 1
Redis The business of
Mybatis Transactions in have four characteristics ,ACID: Atomicity , Uniformity , Isolation, , persistence
but Redis A single command saves atomic , But transactions don't guarantee atomicity
multi#OK, Open transaction
set k1 v1# Set up
set k2 v2# Set up
get k2# Get no value , Only return QUEUE
set k3 v3
exec# perform , Then the return value of the previous command appears , as follows
#1) OK
#2) OK
#3) "v2"
#4) OK
# After each execution, you need to write it again multi
Redis Transaction exception
Compiler exception ( Something is wrong with the code ! There was a mistake in the order !), All commands in the transaction will not be executed !
multi#OK
set k1 v1
getset k2#(error) ERR wrong number of arguments for 'getset' command
set k3 v3
exec#(error) EXECABORT Transaction discarded because of previous errors.
get k2#(nil), empty , Don't do anything
Runtime exception (1/0 One divided by 0), If there are similar exceptions in the transaction queue , So when you execute an order , Other commands can be executed normally , An error command throws an exception
set k1 v1
multi
incr k1# There is no abnormality for the time being , Because the grammar is right
set k2 v2
set k3 v3
get k3
exec# After execution , It can still be executed , It's just incr k1 The statement doesn't work
#1) (error) ERR value is not an integer or out of range
#2) OK
#3) OK
#4) "v3"
Redis Monitoring test ( Optimism lock )
Normal execution succeeded !
set money 100
set out 0
WATCH money# monitor money
MULTI
DECRBY money 20
INCRBY out 20
exec# success , Because there is no other thread interference , as follows , Transfer succeeded
#80
#20
Normal execution is unsuccessful !( Testing multithreaded modification values , Use watch Can be regarded as redis Optimistic lock operation of )
WATCH money
MULTI# Business
DECRBY money 10
INCRBY out 10
exec# Before entering this command , Other thread pairs money It's been modified , Then we entered exec, Then the execution error is displayed
UNWATCH# Unlock
边栏推荐
- Yolov5 input (II) | CSDN creative punch in
- 112 stucked keyboard (20 points)
- Objects. Requirenonnull method description
- Based on RFC 3986 (unified resource descriptor (URI): general syntax)
- [batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
- study hard and make progress every day
- 动态规划——相关概念,(数塔问题)
- How to connect the network: Chapter 1 CSDN creation punch in
- Overview of basic knowledge of C language
- Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
猜你喜欢
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
酒店公共广播背景音乐-基于互联网+的酒店IP网络广播系统设计
BTC-密码学原理
leetcode860. Lemonade change
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
乾元通多卡聚合路由器的技术解析
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
BIO、NIO、AIO区别
联想R7000显卡的拆卸与安装
Go practice -- gorilla / websocket used by gorilla web Toolkit
随机推荐
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
Shuttle + alluxio accelerated memory shuffle take-off
Kept hot standby and haproxy
Problems encountered in fuzzy query of SQL statements
"Pthread.h" not found problem encountered in compiling GCC
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
Compile and decompile GCC common instructions
JS string and array methods
Online VR model display - 3D visual display solution
最大连续子段和(动态规划,递归,递推)
Notes | numpy-07 Slice and index
编译GCC遇到的“pthread.h” not found问题
Go practice -- gorilla / websocket used by gorilla web Toolkit
动态规划——相关概念,(数塔问题)
[develop wechat applet local storage with uni app]
Differences among bio, NiO and AIO
JQ style, element operation, effect, filtering method and transformation, event object
2022-02-11 daily clock in: problem fine brush
SSM framework integration