当前位置:网站首页>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 fList
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,hahaSet
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 15Web 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 1Log 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 multiRedis 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
#20Normal 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 边栏推荐
- Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
- 5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
- MySQL master-slave configuration
- The IntelliJ platform completely disables the log4j component
- [develop wechat applet local storage with uni app]
- 大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
- Notes | numpy-11 Array operation
- 乾元通多卡聚合路由器的技术解析
- 在PyCharm中配置使用Anaconda环境
- Silent authorization login and registration of wechat applet
猜你喜欢

Yolov5 model construction source code details | CSDN creation punch in

Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn

Go practice -- gorilla / websocket used by gorilla web Toolkit

(subplots用法)matplotlib如何绘制多个子图(轴域)

Overview of basic knowledge of C language

(perfect solution) how to set the position of Matplotlib legend freely

Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)

Compile and decompile GCC common instructions
![[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached](/img/01/052928e7f20ca671cdc4c30ae55258.jpg)
[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached

(subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
随机推荐
最大连续子段和(动态规划,递归,递推)
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
[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)
Compile and decompile GCC common instructions
Audio Focus Series: write a demo to understand audio focus and audiomananger
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
(subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
Go language interface learning notes
MySQL master-slave configuration
1087 all roads lead to Rome (30 points)
1115 counting nodes in a BST (30 points)
Shuttle + alluxio accelerated memory shuffle take-off
Class loading mechanism (detailed explanation of the whole process)
Differences among bio, NiO and AIO
cookie session jwt
Realize file download through the tag of < a > and customize the file name
Introduction to rust Foundation (basic type)
BTC-密码学原理
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution