当前位置:网站首页>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 .
边栏推荐
- What does software testing do? What are the requirements for learning?
- How about testing outsourcing companies?
- shell编程基础(第9篇:循环)
- Is it safe for China Galaxy Securities to open an account? Securities account opening
- 不愧是大佬,字节大牛耗时八个月又一力作
- Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
- 软件测试是干什么的?学习有啥要求?
- The problem of returning the longtext field in MySQL and its solution
- 面试官:Redis中集合数据类型的内部实现方式是什么?
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
猜你喜欢
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
Recommended collection, my Tencent Android interview experience sharing
力扣 729. 我的日程安排表 I
软件测试工程师是做什么的?待遇前景怎么样?
力扣 1200. 最小绝对差
Django使用mysqlclient服务连接并写入数据库的操作过程
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
Do you know several assertion methods commonly used by JMeter?
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
随机推荐
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
2022 the latest big company Android interview real problem analysis, Android development will be able to technology
Zhongang Mining: analysis of the current market supply situation of the global fluorite industry in 2022
太牛了,看这篇足矣了
Reinforcement learning - learning notes 4 | actor critical
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
再忙不能忘安全
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
司空见惯 - 英雄扫雷鼠
MMO項目學習一:預熱
Django uses mysqlclient service to connect and write to the database
面试官:Redis中集合数据类型的内部实现方式是什么?
PHP uses ueditor to upload pictures and add watermarks
-v parameter of GST launch
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
软件测试工程师是做什么的?待遇前景怎么样?
Tasks in GStreamer
Fuzor 2020軟件安裝包下載及安裝教程
How to convert word into PDF? Word to PDF simple way to share!
[FAQ] summary of common causes and solutions of Huawei account service error 907135701