当前位置:网站首页>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 is the function of okcc call center
- 国海证券在网上开户安全吗?
- Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array
- Django使用mysqlclient服务连接并写入数据库的操作过程
- What are general items
- Gstreamer中的task
- 全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
- Concept and syntax of function
- Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
- -v parameter of GST launch
猜你喜欢
The city chain technology Digital Innovation Strategy Summit was successfully held
Using repositoryprovider to simplify the value passing of parent-child components
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
How to apply smart contracts more wisely in 2022?
Fuzor 2020軟件安裝包下載及安裝教程
如何在2022年更明智地应用智能合约?
MySql中的longtext字段的返回问题及解决
【无标题】
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
随机推荐
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
The difference between ID selector and class selector
Multi branch structure
Android interview classic, 2022 Android interview written examination summary
How about testing outsourcing companies?
JAD installation, configuration and integration idea
城链科技数字化创新战略峰会圆满召开
HAC cluster modifying administrator user password
Common - Hero Minesweeper
通配符选择器
okcc呼叫中心有什么作用
安卓面试宝典,2022Android面试笔试总结
Concept and syntax of function
Mysql如何对json数据进行查询及修改
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
The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
Hiengine: comparable to the local cloud native memory database engine
MySql中的longtext字段的返回问题及解决
Analysis of openh264 decoded data flow
强化学习-学习笔记4 | Actor-Critic