当前位置:网站首页>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
边栏推荐
- [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)
- 50 practical applications of R language (36) - data visualization from basic to advanced
- Shuttle + alluxio accelerated memory shuffle take-off
- 微服务常见面试题
- "Hands on deep learning" pytorch edition Chapter II exercise
- 1106 lowest price in supply chain (25 points)
- Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
- [practical project] autonomous web server
- [research materials] annual report of China's pension market in 2021 - Download attached
- Compile and decompile GCC common instructions
猜你喜欢
Pessimistic lock and optimistic lock of multithreading
Online VR model display - 3D visual display solution
Basic knowledge of reflection (detailed explanation)
Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
BTC-密码学原理
Source insight garbled code solution
Celebrate the new year together
JS scope
Three representations of signed numbers: original code, inverse code and complement code
随机推荐
SSM framework integration
Principles of BTC cryptography
Introduction to deep learning - definition Introduction (I)
Self introduction and objectives
Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
BTC-密码学原理
Gbase8s composite index (I)
Shuttle + alluxio accelerated memory shuffle take-off
Notes | numpy-07 Slice and index
Interview question -- output the same characters in two character arrays
[develop wechat applet local storage with uni app]
Promise
sql语句模糊查询遇到的问题
Rust基础入门之(基本类型)
appium1.22.x 版本后的 appium inspector 需单独安装
Yolov5 model construction source code details | CSDN creation punch in
JS scope
Wechat applet distance and map
(subplots用法)matplotlib如何绘制多个子图(轴域)
Learn libcef together -- set cookies for your browser