In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the underlying implementation method of redis five data structures". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "the bottom implementation method of redis five data structures"!
Implementation methods: 1. Each data structure has its own underlying internal coding implementation, and it is a variety of implementations, so Redis will select the appropriate internal coding in the appropriate scene;2. Each data structure has more than two internal coding implementations;3. Internal coding can be used as an internal implementation of multiple external data structures.
This tutorial operating environment: Windows 7 system, Redis 5.0.10 version, DELL G3 computer.
Redis has five basic data structures: string, hash, set, zset, list. The following explains how the underlying implementation of Redis 3.0.6 is downloaded.
summarize
(1) Each data structure has its own underlying internal coding implementation, and there are multiple implementations, so that Redis will choose the appropriate internal coding in the appropriate scenario.
(2) You can see that each data structure has more than two internal encoding implementations, for example, string data structure contains raw, int and embstr three internal encoding.
(3) At the same time, some internal codes can be used as internal implementations of multiple external data structures, such as ziplist, which is the internal code common to hash, list, and zset.
Dynamic String SDS
SDS stands for "simple dynamic string." All strings appearing in Redis are basically implemented by SDS:
All non-numeric keys, e.g. key msg in set msg "hello"
String data type value, e.g. value "hello" in set msg "hello"
"String value" in non-string data types, e.g."apple" "banana" in push fruits "apple" "banana"
SDS looks like this:
Free: How much space is left?
len: string length
buf: array of stored characters
spatial preallocation
To reduce the number of memory reallocations required to modify string proxies, SDS uses a one-shot strategy:
If SDS length after modification
< 1MB,则多分配现有len长度的空间 若修改之后SDS长度 >= 1MB, then the expansion meets the modified length and has an additional 1MB of space.
inert space release
To avoid memory reallocation operations when shortening strings, SDS does not immediately free space when data is reduced.
int
It means all kinds of numbers stored in redis, including deliberately added ""
set game "111"
doubly linked list
Double-linked lists such as lpush, rpush, lpop, rpop
It looks like this:
It is divided into two parts:
"Overall section": orange
head: points to the head of a specific doubly linked list
tail: Pointing to the tail of a specific doubly linked list
len: Length of doubly linked list
"By": blue
There are pre and next.
A doubly linked list consists of two data structures: list and listNode.
At this point, I believe that everyone has a deeper understanding of the "underlying implementation method of redis five data structures". It is advisable to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.