当前位置:网站首页>Interviewer: what is the internal implementation of ordered collection in redis?
Interviewer: what is the internal implementation of ordered collection in redis?
2022-07-06 20:57:00 【51CTO】
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 an ordered set ?
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 .
Internal implementation of ordered sets
There are two internal implementations of ordered sets , Namely : Compressed list (ziplist) And the jump watch (skiplist). Next , Let's have a detailed understanding of .
Take the compressed list as the internal implementation
When the number of elements in an ordered set is less than zset-max-ziplist-entries
( The default is 128 individual ), And the length of each element member is less than zset-max-ziplist-value
( The default is 64 byte ) When , Use a compressed list as an internal implementation of an ordered set .
Each set element consists of two compressed list nodes next to each other , The first node holds the members of the element , The second node holds the branch of the element . The elements in the compressed list are arranged next to each other according to the score from small to large , Effectively reduce the use of memory space .
for instance , We use zadd
Command to create an ordered collection implemented as a compressed list :
Take the jump table as the internal implementation
When the number of elements in an ordered set is greater than or equal to zset-max-ziplist-entries
( The default is 128 individual ), Or the length of each element member is greater than or equal to zset-max-ziplist-value
( The default is 64 byte ) When , Use the jump table as the internal implementation of the ordered set .
here , In fact, there are two structures in an ordered set , One is the jump table , The other is the hash table .
In the jump table , All elements are arranged from small to large . In the node of the jump table object
Pointer to the string object of the element member ,score
Saved the score of the element . Through the jump table ,Redis You can quickly score and range ordered sets 、 Ranking and other operations .
In the hash table , A mapping from element members to element fractions is created for ordered collections . The key in the key value pair points to the string object of the element member , The value in the key value pair holds the score of the element . Through hash table ,Redis You can quickly find the score of the specified element .
Although ordered collections use both jump tables and hash tables , But both data structures use pointers to share members and scores in elements , No extra memory waste .
for instance , We use zadd
Command to create an ordered set implemented by jump table :
Internally implemented transformation
When an ordered set is implemented internally with a compressed list , Then add a longer element member to the ordered set , Or when there are too many elements in this ordered set , Then the ordered set will be transformed into an internal implementation with a jump table . however , An ordered set with a jump table as an internal implementation will not be converted to a compressed list as an internal implementation .
for instance , Let's first create an ordered collection with a compressed list as the internal implementation :
then , Add a longer member element to it , It is converted to take the jump table as the internal implementation :
then , Then remove the element of the longer member from the ordered set , An ordered set is still implemented internally with a jump table :
summary
stay Redis in , The internal implementation of an ordered set has a compressed list (ziplist) And the jump watch (skiplist) Two kinds of , When the member length of all elements in the collection is short and the number of elements is small , Use a compressed list as an internal implementation , Otherwise, use the jump table and hash table as the internal implementation . When conditions are not met , The compressed list can be converted into a jump table , But the jump table cannot be converted to a compressed list .
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 .
边栏推荐
- Function optimization and arrow function of ES6
- Laravel笔记-自定义登录中新增登录5次失败锁账户功能(提高系统安全性)
- Yyds dry goods count re comb this of arrow function
- Entity alignment two of knowledge map
- use. Net drives the OLED display of Jetson nano
- R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
- [DIY]如何制作一款个性的收音机
- 【每周一坑】计算100以内质数之和 +【解答】输出三角形
- #yyds干货盘点#重新梳理箭头函数的this
- Leetcode hot topic Hot 100 day 32: "minimum coverage substring"
猜你喜欢
(work record) March 11, 2020 to March 15, 2021
Core principles of video games
Trends of "software" in robotics Engineering
use. Net analysis Net talent challenge participation
Reinforcement learning - learning notes 5 | alphago
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
Logic is a good thing
[weekly pit] information encryption + [answer] positive integer factorization prime factor
[DIY]如何制作一款個性的收音機
逻辑是个好东西
随机推荐
[diy] self designed Microsoft makecode arcade, official open source software and hardware
SAP UI5 框架的 manifest.json
[200 opencv routines] 220 Mosaic the image
#yyds干货盘点#重新梳理箭头函数的this
使用.Net分析.Net达人挑战赛参与情况
2022 refrigeration and air conditioning equipment installation and repair examination contents and new version of refrigeration and air conditioning equipment installation and repair examination quest
Can novices speculate in stocks for 200 yuan? Is the securities account given by qiniu safe?
【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和
OAI 5G NR+USRP B210安装搭建
Dynamically switch data sources
Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition
全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
面试官:Redis中有序集合的内部实现方式是什么?
Rhcsa Road
[weekly pit] output triangle
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
Xcode6 error: "no matching provisioning profiles found for application"
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
New database, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, Feishu multidimensional table, heipayun, Zhixin information, YuQue
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀