当前位置:网站首页>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
边栏推荐
- #yyds干货盘点# 面试必刷TOP101:链表中的节点每k个一组翻转
- LeetCode_位运算_中等_260.只出现一次的数字 III
- 根据openGauss/MogDB的lwtid查看线程堆栈。
- 字符设备驱动结构
- [C language] use function pointers to make a different calculator
- 树行表达方式
- Leetcode-297 serialization and deserialization of binary tree
- How to make the design of governance structure more flexible when the homogenization token is combined with NFT?
- Use of DDR3 (axi4) in Xilinx vivado (4) incentive design
- DHCP.DNS.NFS
猜你喜欢

Nocturnal simulator settings agent cannot be saved

太空射击第11课: Sound and Music

Raspberry connects EC20 for PPP dialing

PXE_ KS unattended system
![[C语言刷题篇]链表运用讲解](/img/44/1de4e3f0712780680fbdc904dfe39a.png)
[C语言刷题篇]链表运用讲解

LVM logical volume

Unity package exe to read and write excel table files

LeetCode-297-二叉树的序列化与反序列化

Read JSON configuration file to realize data-driven testing

CNN convolutional neural network structure
随机推荐
弹出模态框
Network shell
Networkx common operations summary (for personal use)
Sorting out problems in interface endpoint testing practice using Supertest
Raspberry pie 4B parsing PWM
Solve the problem that the nocturnal simulator cannot access the Internet after setting an agent
Mongoose condition queries the data of a certain time period
Wust-ctf2021-re school match WP
Vivado design single cycle CPU
Unity package exe to read and write excel table files
LeetCode-297-二叉树的序列化与反序列化
Unity uses shader to quickly make a circular mask
动态规划:背包问题模板代码汇总
[task01: getting familiar with database and SQL]
产品力大幅提升 新款福特探险者发布
Redis入门一:Redis实战读书笔记
Three steps to teach you unity serial communication
js win7透明桌面切换背景开始菜单js特效
Linxu [permission, sticky bit]
Commands related to obtaining administrator permissions