当前位置:网站首页>Introduction to redis II: RedHat 6.5 installation and use
Introduction to redis II: RedHat 6.5 installation and use
2022-07-28 20:39:00 【51CTO】
Redis The server
Redis There will be one in the directory redis.conf The configuration file , It's inside Redis Default configuration , Generally speaking, we will start multiple... On one machine Redis, And centrally manage the configuration in the specified directory , Handwritten configuration... And not completely handwritten , It's going to be redis.conf Modify as a template .
Use the configuration file to start :redis-server redis.conf The path of /redis.confRedis Command line client
C/C++ operation Redis Use hiredis
Redis There are two advantages to this design : First of all , Internal coding can be improved , And the external data structure and command have no influence , So once you develop better internal code , There is no need to change the external data structure and commands , for example Redis3.2 Provides quicklist, Combined with the ziplist and linkedlist Advantages of both , Provides a better internal coding implementation for list types , For external users, it is almost imperceptible . second , A variety of internal coding implementations can play their own advantages in different scenarios , for example ziplist More memory saving , But when there are more list elements , There will be a drop in performance , Now Redis The internal implementation of the list type is converted to linkedlist.
The internal encoding of a string type is 3 Kind of :int(8 A long integer of bytes )、embstr( Less than or equal to 39 A byte string )、raw( Greater than 39 A byte string ).
The internal codes of list types are 2 Kind of :
ziplist( Compressed list ) When the number of elements in the list is less than list-max-ziplist-entries To configure ( Default 512 individual )、 At the same time, the value of each element in the list is less than list-max-ziplist-value To configure ( Default 64 byte ) when ,Redis Will use ziplist As an internal implementation of hash to reduce memory usage .
linkedlist( Linked list ) When the list type cannot satisfy ziplist The condition of ,Redis Will use linkedlist As an internal implementation of the list .
Redis 3.2 Version provides quicklist Internal encoding , To put it simply, it takes a ziplist For node linkedlist, It is a combination of ziplist and linkedlist Advantages of both .
The internal encoding of hash type is 2 Kind of :
ziplist( Compressed list ) When the number of hash type elements is less than hash-max-ziplist-entries To configure ( Default 512 individual )、 At the same time, all values are less than hash-max-ziplist-value To configure ( Default 64 byte ) when ,Redis Will use ziplist As an internal implementation of hash ,ziplist Use a more compact structure to achieve continuous storage of multiple elements , So in terms of saving memory hashtable Better .
hashtable( Hashtable ) When the hash type cannot be satisfied ziplist The condition of ,Redis Will use hashtable As an internal implementation of hash , So now ziplist The efficiency of reading and writing will decrease , and hashtable The time complexity of reading and writing is O(1).
There are two types of internal encoding for collection types :
intset( Set of integers ) When all the elements in the set are integers and the number of elements is less than set-max-intset-entries To configure ( Default 512 individual ) when ,Redis Will choose intset As an internal implementation of a collection , Thus reducing the use of memory .
hashtable( Hashtable ) When the set type cannot satisfy intset The condition of ,Redis Will use hashtable As an internal implementation of a collection .
There are two kinds of internal codes for ordered set types :
ziplist( Compressed list ) When the number of elements in an ordered set is less than zset-max-ziplist-entries To configure ( Default 128 individual ), At the same time, the value of each element is less than zset-max-ziplist-value To configure ( Default 64 byte ) when ,Redis Will use ziplist As an internal implementation of an ordered set ,ziplist Can effectively reduce the use of memory .
skiplist( Skip list ) When ziplist When the conditions are not met , Ordered sets will use skiplist As an internal implementation , So now ziplist The efficiency of reading and writing will decrease .
Use scenarios for lists :
lpush+brpop The command combination can block the queue , The producer client uses lpush Insert elements from the left side of the list , Multiple consumer clients use brpop Command blocking grabs the elements at the end of the list .
data structure | Whether duplicate elements are allowed | Is it orderly | Orderly implementation | Storage | Application scenarios |
list | yes | yes | Index the following table | value | time axis 、 Message queuing, etc |
Hash | no | no | nothing | Key value | |
aggregate | no | no | nothing | value | label 、 Social, etc |
Ordered set | no | yes | fraction | Key value | Ranking system 、 Social, etc |
Redis It is a single thread to process commands , A command from the client to the server will not be executed immediately , All commands go into a queue , And then it's executed one by one . The execution order of multiple client commands is uncertain , But no two commands will be executed at the same time .Redis Use epoll As I/O The realization of multiplexing technology , Plus Redis Its own event handling model will epoll Connection in 、 Reading and writing 、 Close all converted to events , Not in the network I/O Waste too much time on .
The communication protocol between client and server is TCP Built on top of the agreement .Redis Formulated the RESP(Redis Serialization Protocol,Redis Serialization protocol ) Realize the normal interaction between the client and the server .
Redis 3.0 Chinese annotation
https://github.com/huangz1990/redis-3.0-annotated
边栏推荐
- 超大模型工程化实践打磨,百度智能云发布云原生AI 2.0方案
- Raspberry pie 3b ffmpeg RTMP streaming
- Shanghai Jiaotong University joined hands with Taobao to set up a media computing laboratory: promoting the development of key technologies such as video super score
- Linxu 【基本指令】
- 产品经理访谈 | 第五代验证码的创新与背景
- 弹出模态框
- Raspberry pie 4B uses MNN to deploy yolov5 Lite
- Raspberry pie uses the command line to configure WiFi connections
- MySQL batch update data
- C language data 3 (1)
猜你喜欢
随机推荐
[C language] guessing numbers game
Representation of base and number 2
太空射击第10课: Score (繪畫和文字)
Pytorch model parameter assignment - tensor.copy_ () method
Unity uses shader to quickly make a circular mask
Regular symbol description
SQL审核工具自荐Owls
Explain RESNET residual network in detail
Common commands of raspberry pie
LVS load balancing cluster
一碰撞就自燃,谁来关心电池安全?上汽通用有话说
Raspberrypico serial communication
The product power is greatly improved, and the new Ford Explorer is released
C language data 3 (2)
微信公众号授权登录后报redirect_uri参数错误的问题
js win7透明桌面切换背景开始菜单js特效
User and group and authority management
Classes and objects (medium)
Raspberry pie 4B deploy yolov5 Lite using ncnn
js图表散点图例子