当前位置:网站首页>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 边栏推荐
- Go practice -- use JWT (JSON web token) in golang
- [basic grammar] C language uses for loop to print Pentagram
- [backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
- (完美解决)matplotlib图例(legend)如何自由设置其位置
- [Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
- Pan details of deep learning
- SSM framework integration
- Force GCC to compile 32-bit programs on 64 bit platform
- 【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
- Introduction to deep learning (II) -- univariate linear regression
猜你喜欢

联想R7000显卡的拆卸与安装
![[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)](/img/34/d195752992f8955bc2a41b4ce751db.jpg)
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)

Silent authorization login and registration of wechat applet

Gbase8s unique index and non unique index

Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis

appium1.22. Appium inspector after X version needs to be installed separately

Pan details of deep learning

Differences among bio, NiO and AIO

Shallow and first code

Common interview questions of microservice
随机推荐
Notes | numpy-08 Advanced index
Gbase8s unique index and non unique index
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
Go practice -- generate and read QR codes in golang (skip2 / go QRcode and boombuilder / barcode)
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
XML Configuration File
JS scope
leetcode406. Rebuild the queue based on height
Redis 入门和数据类型讲解
Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
[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)
Online VR model display - 3D visual display solution
Shallow and first code
微服务常见面试题
The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
Webrtc native M96 version opening trip -- a reading code download and compilation (Ninja GN depot_tools)
动态规划——相关概念,(数塔问题)
1118 birds in forest (25 points)
Kept hot standby and haproxy
appium1.22.x 版本后的 appium inspector 需单独安装