当前位置:网站首页>Interviewer: what is the internal implementation of set data types in redis?
Interviewer: what is the internal implementation of set data types in redis?
2022-07-05 19:45:00 【51CTO】
Although it is already March in spring , But riding a shared bike so far , And a little cold . I rubbed my frozen numb hands , Say to the lady at the front desk :“ Hello! , I'm here for an interview .”
Miss asked :“ Hello! , What's your name ?” I reply :“ My name is wanmao society .” Miss, sister laughed , Speaking of :“ That's a strange name , Who gave it to you .” I replied without expression :“ My father .” The little sister put away her smile , Speaking of :“ Come with me .” I was taken to the interview room to wait , A moment later, a young man with a clean and beautiful face came in , A faint fragrance of men's perfume comes to us. .
interviewer :Redis What are the basic data types in ?
I :Redis The basic data types of are : character string (string)、 Hash (hash)、 list (list)、 aggregate (set)、 Ordered set (zset).
interviewer : What is the internal implementation of the collection data type ?
I was also immersed in the complacency of the last question , Suddenly, his expression solidified , The palms began to sweat .“ This .. Not much in-depth understanding ”, I hesitated .
interviewer : Go back and wait for the news .
This sentence is clear , And then there's no then . Failure is the mother of success , I'm not discouraged , Decided to mend it right away .
Type and code
First , Understand what is type ? What is? code ? stay Redis Objects are used in to represent keys and values in memory . Each object consists of a redisObject
The structure represents , There are three properties : type (type)、 code (encoding)、 Pointer to specific data (ptr).
We usually say string 、 Hash 、 list 、 aggregate 、 Ordered sets are redisObject
Medium type , In fact, for each data structure Redis There are various internal coding implementations at the bottom of the system , This is to select the appropriate internal code in the appropriate scene , To achieve a balance between memory space and processing efficiency , This may be the golden mean .
In the interview , Often asked about the internal implementation 、 Internal construction 、 internals , Generally speaking, it means redisObject
Medium code .
The encoding of the set
There are two kinds of codes for sets , Namely : Set of integers (intset) Hash table (hashtable).
When all elements in a set are integers , And the number of elements is less than set-max-intset-entries
( The default is 512 individual ) when , Use an integer set as the encoding of the set , All integers are stored in the set of elements . such as :
When all elements in the set are not integers , Or the number of elements is greater than or equal to set-max-intset-entries
( The default is 512 individual ) when , Use the hash table as the encoding of the set , Each key in the hash table is a string object , Each string contains a collection of elements , The values of the hash table are all NULL
.
such as , All elements in the collection are not integers :
Of course , I haven't fully understood the above details yet “ conquer ” interviewer , We need to go deeper :)
Encoding conversion of sets
When a set is encoded as an integer set , Then add non integer elements to this set , Or add integer elements to this set, so that the number of elements is too large , Will perform the encoding conversion of the set .
Transfer all elements originally saved in the integer set to the hash table , And the encoding of the set is changed from an integer set to a hash table . however , Remove non integer elements from the set , Or reduce the number of integer elements , A set encoded by a hash table will not be converted to an integer set .
for instance , Let's first create a set encoded by an integer set :
then , Add two more string elements to it , It is converted to hash table encoding :
then , Then remove the two string elements from the collection , The encoding of the set is still a hash table :
summary
stay Redis in , The internal implementation of the set has an integer set (intset) Hash table (hashtable) Two kinds of , When all elements in the set are integers and the number of elements is small , Use the integer set as the internal implementation , Otherwise, use the hash table as the internal implementation . When conditions are not met , An integer set can be converted to a hash table , But the hash table cannot be converted to an integer set .
I've seen it here , You and I must be predestined friends , Leave your give the thumbs-up and Focus on , It will become a great thing in the future .
边栏推荐
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- 常用运算符与运算符优先级
- Worthy of being a boss, byte Daniel spent eight months on another masterpiece
- Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
- 软件测试工程师是做什么的?待遇前景怎么样?
- Relationship between floating elements and parent and brother boxes
- Necessary skills for interview in large factories, 2022android will not die, I will not fall
- Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
- Concept and syntax of function
- okcc呼叫中心有什么作用
猜你喜欢
Fuzor 2020軟件安裝包下載及安裝教程
What are the reliable domestic low code development platforms?
The city chain technology Digital Innovation Strategy Summit was successfully held
Apprentissage du projet MMO I: préchauffage
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
No matter how busy you are, you can't forget safety
Django uses mysqlclient service to connect and write to the database
如何安全快速地从 Centos迁移到openEuler
Using repositoryprovider to simplify the value passing of parent-child components
Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
随机推荐
Common - Hero Minesweeper
PHP利用ueditor实现上传图片添加水印
大厂面试必备技能,2022Android不死我不倒
40000 word Wenshuo operator new & operator delete
Hiengine: comparable to the local cloud native memory database engine
How to apply smart contracts more wisely in 2022?
深度学习 卷积神经网络(CNN)基础
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
Fuzor 2020软件安装包下载及安装教程
太牛了,看这篇足矣了
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
What is the core value of testing?
司空见惯 - 英雄扫雷鼠
What is the function of okcc call center
国海证券在网上开户安全吗?
okcc呼叫中心有什么作用
爬虫练习题(二)
全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
Password reset of MariaDB root user and ordinary user