当前位置:网站首页>Quickly understand what the dictionary in redis is
Quickly understand what the dictionary in redis is
2022-04-22 14:32:00 【Wanmao Society】
Dictionary Introduction
A dictionary is a data structure used to hold key value pairs , You can quickly find the corresponding value through the key in the key value pair . stay Redis What is used C In language , No built-in dictionary , therefore Redis I realized the dictionary myself .
Whole Redis All the keys and values of the database form a global dictionary , The operations of adding, deleting, modifying and querying the database are all based on the operation of the dictionary .
Dictionary or Redis Basic data type hash (hash) One of the underlying implementations of , When the length of keys and values of hash data type is large or the number of key value pairs is large ,Redis The dictionary will be used as the underlying implementation of hash data type .
Dictionary or Redis An ordered collection of basic data types (zset) One of the underlying implementations of , When the member length of all elements in the ordered set is long or the number of elements is large ,Redis The jump table and hash table will be the internal implementation of the ordered set .
Dictionary implementation
stay Redis The dictionary in is made up of dict Structure means , Its underlying implementation uses a hash table , A hash table contains multiple hash table nodes , Each hash table node stores a key value pair in the dictionary . Now let's take a detailed look at one by one .
Dictionary structure
Dictionaries are written by dict Structure means , It contains the following properties :
typeattribute : A pointer to adictTypePointer to structure , EverydictTypeStructures store a set of functions for their specific type of key value pair operation .privdataattribute : Save the optional parameters that need to be passed to its specific type function .htattribute : An array of two items , Each item is a hash table . In general , The dictionary only uses the first hash table , Only after re hashing (rehash) The second hash table is only used when .rehashidxattribute : Used to record rehash (rehash) Progress , When there is no hashing (rehash) When , Its value is -1.
among ,type Properties and privdata After attribute combination , You can do different processing operations for different types of key value pairs , such as : Calculate the hash value 、 Copy key 、 Copy value 、 Contrast key 、 Destroy key 、 Destroy value, etc .
Hashtable
Hash table use dictht Structural representation , It contains the following properties :
tableattribute : A hash table array , Each item in the array is a pointer to the hash table node , Each hash table node stores a key value pair in the dictionary .sizeattribute : The size of the hash table , That is, hash table array (table) Size .sizemaskattribute : Hash table size mask , Used to calculate index values , Always equal to hash table size (size)-1.usedattribute : The number of existing nodes in the hash table .
Hash table node
Hash table nodes use dictEntry Structural representation , It contains the following properties :
keyattribute : Used to save the key in the key value pair .vattribute : Used to save the value in the key value pair . It can be a pointer , It can also be auint64_tThe integer of , It can also be aint64_tThe integer of .nextattribute : A pointer to the next hash table node . When there is a key conflict , It can connect multiple hash table nodes , Form a one-way list .
Dictionary example
Said so much , Are relatively abstract and not easy to understand , Let's give you an example :
This is the internal structure of a dictionary , Among them is 3 Key value pairs , The keys are : ten thousand 、 cat 、 study group .
版权声明
本文为[Wanmao Society]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221427283302.html
边栏推荐
- 数据库SQL实战全解
- Apache IoTDB’s UDF源碼分析(1)
- In depth analysis of lock and AQS
- Arcengine点,线,面,文本渲染
- Deep understanding of read-write lock reentrantreadwritelock and concurrent container copyonwritearraylist
- Applying stochastic processes 09: discrete time Martingales
- 2020 popular whole network series: This is a very suitable Android advanced - interview key and difficult data notes for collection and collection! Continuously update the high-quality interview links
- 华为云媒体査勇:华为云在视频AI转码领域的技术实践
- 如何配置 SLO
- Knowledge is power, but more importantly, the ability to use knowledge - wechat code scanning payment on the web - technical design
猜你喜欢

Borui data and F5 jointly build the full data chain DNA of financial technology from code to user

Arcengine打印视图与布局视图原理解析

获取数组中每一项对象中的某个值的和(reduce的使用)

Deep understanding of read-write lock reentrantreadwritelock and concurrent container copyonwritearraylist
26 years old, 0 basic software testing still in time

C#编写BS接口环境部署及开发调试方法
985 Shuo's difficult transition to Android, plus face-to-face experience sharing, meituan Android interview

3. fiddler证书安装和抓取hettps设置

Huawei cloud media Zha Yong: Huawei cloud's technical practice in the field of video AI transcoding

dxg:TableView.FormatConditions 表格按条件高亮显示
随机推荐
Difference between NPM install -- save and NPM install -- save dev
spark代码 spark-submit提交yarn-cluster模式
Apache IoTDB’s UDF源码分析(1)
The sum of the k-th queen arrangement and the i-th queen arrangement
pip命令和在线、离线安装方法
ArcEngine符号相关
Series interpretation of smc-r (II): smc-r communication technology integrating TCP and RDMA
ArcEngine line to face conversion
Deep understanding of read-write lock reentrantreadwritelock and concurrent container copyonwritearraylist
LeetCode刷题(04)
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
云原生架构下的微服务选型和演进
26 years old, 0 basic software testing still in time
Detailed explanation of kubernetes (VI) -- pod object deployment and Application
做好安全测试的方法
shell入门使用
Android 92022-2022 byte beating Android interview real question analysis
Ladder race -- l2-004 is this a binary search tree? (25 points) (recursive)
CorelDRAW插件-CPG插件开发-环境搭建-VS2017-TLB文件-CDR插件
Double pointer 𞓜 ordered array to reorder the linked list and remove elements 26, 27 and 83