当前位置:网站首页>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
边栏推荐
- The engineering practice of super large model was polished, and Baidu AI Cloud released the cloud native AI 2.0 solution
- [C language] 5000 word super detailed explanation of various operations of the sequence table
- 产品力大幅提升 新款福特探险者发布
- GRU神经网络
- Regular symbol description
- 企业如何成功完成云迁移?
- CNN convolutional neural network structure
- 【CodeForces】Educational Codeforces Round 132 (Rated for Div. 2)
- Pytorch model parameter assignment - tensor.copy_ () method
- [task03: complex query methods - views, subqueries, functions, etc.]
猜你喜欢
![[fasttext -- Summary notes]](/img/4d/2871b2525bf0ea75ee958338b18013.png)
[fasttext -- Summary notes]

Unity uses shader to quickly make a circular mask

Use of DDR3 (axi4) in Xilinx vivado (1) create an IP core

C language data 3 (2)

LVS load balancing cluster

Speech controlled robot based on ROS (I): realization of basic functions

Product manager interview | innovation and background of the fifth generation verification code

如何平衡SQL中的安全与性能?
关于链接到其他页面的标题

太空射击第11课: Sound and Music
随机推荐
Database tuning - connection pool optimization
Simple example of C language 1
Solve the problem that the nocturnal simulator cannot access the Internet after setting an agent
[task03: complex query methods - views, subqueries, functions, etc.]
Extract China map from global.Nc data and calculate regional CO2 value based on acgis
Raspberry connects EC20 for PPP dialing
Network shell
UE4.25 Slate源码解读
Solve the problem that jupyter cannot import new packages
超大模型工程化实践打磨,百度智能云发布云原生AI 2.0方案
Voice controlled robot based on ROS (II): implementation of upper computer
华为云数字资产链,“链”接数字经济无限精彩
Raspberry pie 4B uses MNN to deploy yolov5 Lite
Use of DDR3 (axi4) in Xilinx vivado (3) module packaging
平均海拔4000米!我们在世界屋脊建了一朵云
一文让你搞懂什么是TypeScript
太空射击第15课: 道具
C language data 3 (1)
微信公众号授权登录后报redirect_uri参数错误的问题
h5微信射击小游戏源码