当前位置:网站首页>Basic data structure of redis
Basic data structure of redis
2022-07-01 00:22:00 【ordinaryBlog】
Redis The basic data structure
data structure
string( character string )
Redis The string of is a dynamic string , Is a string that can be modified , The internal structure is similar to Java Of ArrayList, Reduce the frequent allocation of memory by pre allocating redundant space
When the string length is less than 1M when , Double the capacity , exceed 1M Every expansion 1M, Maximum length is 512M
It can be used to cache user information
list( list )
Redis Medium list amount to Java Of LinkedList, Insert and delete as O(1) , Index positioning is slow , The time complexity is O(n)
list Structure can be used as an asynchronous queue , Sequence the task structures that need to be delayed into strings and insert them into Redis A list of .
hash( Dictionaries )
amount to Java Of HashMap, It's an unordered Dictionary , Is the structure of array and linked list
The difference is :hash The value of can only be a string , And their rehesh Different ,HashMap When the dictionary is big ,rehash It's a time-consuming job , All at once rehash.Redis To prevent blocking services for high performance , Progressive rehash Strategy , That is to say rehash While preserving the old and new structures , Two will be queried at the same time hash structure , And then on the following scheduled tasks and hash Of the , Gradually replace the old hash A little bit of content migrated to the new hash In structure .
shortcoming :hash Structure consumes more storage than a single string
set( aggregate )
Redis The set of is equivalent to Java Linguistic HashSet, Internal key value pairs are unordered and unique , Equivalent to a special hash,value by NULL.
Can be used to store the... Of the winning users in the event ID, Guarantee that the same user won't win twice
zset( Ordered list )
Be similar to Java Of SortedSet and HashMap The combination of , You can assign a sort weight to each value score. The internal implementation is implemented with a jump table or a compressed list
Can be used to store Fans list value The value of is fans ID,score It's about time
Compressed list
When zset Saved elements are less than 128 And all elements are less than 64 Byte time , Encoded as ziplist
At this time, the ordered collection object uses the compressed list as the underlying implementation
Each collection element uses two packed list nodes next to each other to hold , The first node holds the members of the element , The second node holds the score of the element . And the set elements in the compressed list are arranged in the order of score from small to large , Place the small one near the meter head , Place the large one near the end of the watch . The dictionary key holds the value of the element , The dictionary value holds the score of the element .
Jump watch :
The jump table is a randomized data structure , In fact, it is an ordered linked list that can be used for binary search ;
Jump table in the original ordered list above the addition of multi-level index , Fast search by index
Skipping tables not only improves search performance , It can also improve the performance of insert and delete operations O(log n)
Jump table node object Property holds the members of the element , Jump table node score Attribute holds the score of the element .
Share members and scores of the same element through pointers , So there will be no repetition , It's a waste of memory
Why use a jump table instead of a red black tree
redis Ordered set support
- Insert elements
- Remove elements
- Look for the element
- Output all elements in order
- Find all elements in the interval
The first four red and black trees can be completed , And the time complexity is the same as that of the skip table , But for the last item, the efficiency of red black tree is not as high as that of jump table .
In the jump table , To find the elements of an interval , We just need to locate the two interval endpoints at the bottom , Then traverse it , The red black tree can only locate the endpoint, and then start from the first position. Each time, it must find the subsequent nodes , It's relatively time-consuming
Besides , The implementation of jump table is relatively easy and readable , It is difficult to implement the red black tree , therefore Redis Choose to use a skip table to implement an ordered set
边栏推荐
- 2022-2028 global public address fire alarm system industry research and trend analysis report
- Five minutes to understand the exploratory test
- Red hat will apply container load server on project atomic
- Explain kubernetes backup and recovery tools velero | learn more about carina series phase III
- Examples of topological sequences
- Ditto set global paste only text shortcuts
- Mysql database query optimization
- Thoughts on the future of data analysis in "miscellaneous talk"
- 20220216 misc buuctf backdoor killing (d shield scanning) - clues in the packet (Base64 to image)
- 2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report
猜你喜欢

Analysis of 8253a register

Combining online and offline, VR panorama is a good way to transform furniture online!

6-1 exploit -ftp exploit

Gateway service gateway

Maxpool2d explanation -- Application in arrays and images

2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report

CentOS installation starts redis

2022-2028 global encrypted external hard disk industry research and trend analysis report

When is it appropriate to replace a virtual machine with a virtual machine?

The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?
随机推荐
"Experience" my understanding of user growth "new users"
Is it safe to open a stock account of Huatai Securities online?
New trend of embedded software development: Devops
Operation record of reinitialization instance of Dameng database
When is it appropriate to replace a virtual machine with a virtual machine?
leetcode 474. Ones and zeroes (medium)
LVM snapshot: backup based on LVM snapshot
Tide - rust web framework based on async STD
2022-2028 global mobile scanning radiology room industry survey and trend analysis report
The full technology stack, full scene and full role cloud native series training was launched to help enterprises build a hard core cloud native technology team
CentOS install MySQL
5g smart building solution 2021
76 page comprehensive solution 2022 for smart Logistics Park (download attached)
What SQL statements are supported for data filtering
让企业数字化砸锅和IT主管背锅的软件供应链安全风险指北
C /platform:anycpu32bitpererrored can only be used with /t:exe, /t:winexe and /t:appcontainerexe
1175. 质数排列 / 剑指 Offer II 104. 排列的数目
How to use robots Txt and its detailed explanation
Bridge emqx cloud data to AWS IOT through the public network
[untitled]