当前位置:网站首页>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
边栏推荐
- Networkx common operations summary (for personal use)
- 7/27 训练日志(位运算+后缀数组)
- Use of DDR3 (axi4) in Xilinx vivado (5) board test
- Pytorch model parameter assignment - tensor.copy_ () method
- LeetCode_位运算_中等_260.只出现一次的数字 III
- Other IPS cannot connect to the local redis problem solving and redis installation
- Unity uses shader to quickly make a circular mask
- C# 委托 delegate 的理解
- [pytorch] LSTM neural network
- Solve the problem that jupyter cannot import new packages
猜你喜欢

一文了解 Rainbond 云原生应用管理平台

DOS common commands

Leetcode-297 serialization and deserialization of binary tree

LVS deployment Dr cluster

Wust-ctf2021-re school match WP

上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展

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

Linxu 【权限,粘滞位】

Unity package project to vs deploy hololens process summary

Use of DDR3 (axi4) in Xilinx vivado (1) create an IP core
随机推荐
Linxu [permission, sticky bit]
LeetCode_位运算_中等_260.只出现一次的数字 III
Music says
js win7透明桌面切换背景开始菜单js特效
CNN convolution neural network learning process (weight update)
About the title of linking to other pages
Nocturnal simulator settings agent cannot be saved
激光slam:LeGO-LOAM---代码编译安装与gazebo测试
User, user group related operations
Data mining (data preprocessing) -- Notes
SQL审核工具自荐Owls
产品经理访谈 | 第五代验证码的创新与背景
Redis入门二:redhat 6.5安装使用
Raspberry pie 4B parsing PWM
Classes and objects (medium)
LVS deployment Dr cluster
The engineering practice of super large model was polished, and Baidu AI Cloud released the cloud native AI 2.0 solution
Windows系统下Mysql数据库定时备份
读取json配置文件,实现数据驱动测试
MySQL batch update data