当前位置:网站首页>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
边栏推荐
- New trend of embedded software development: Devops
- 2022-2028 global elevator emergency communication system industry research and trend analysis report
- Redis - how to understand publishing and subscribing
- [untitled]
- 5g smart building solution 2021
- lvm-snapshot:基于LVM快照的备份之准备工作
- 2022-2028 global rampant travel industry research and trend analysis report
- BeanUtils. Copyproperties() vs. mapstruct
- CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
- 女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
猜你喜欢
Combining online and offline, VR panorama is a good way to transform furniture online!
20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
The programmer's girlfriend gave me a fatigue driving test
2022-2028 global capsule shell industry research and trend analysis report
2022-2028 global rampant travel industry research and trend analysis report
IFLYTEK active competition summary! (12)
2022-2028 global encrypted external hard disk industry research and trend analysis report
Development of wireless U-shaped ultrasonic electric toothbrush
C WinForm program interface optimization example
Error 2059 when Navicat connects to MySQL
随机推荐
20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
[PHP] self developed framework qphp, used by qphp framework
Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
Error 2059 when Navicat connects to MySQL
CTF tool (1) -- archpr -- including installation / use process
2022-06-30: what does the following golang code output? A:0; B:2; C: Running error. package main import “fmt“ func main()
2022-2028 global ultra high purity electrolytic iron powder industry research and trend analysis report
20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
Is it safe to choose mobile phone for stock trading account opening in Guangzhou?
Ybtoj exchange game [tree chain splitting, line segment tree merging]
Explain kubernetes backup and recovery tools velero | learn more about carina series phase III
五分钟搞懂探索式测试
Can SQL execution be written in tidb dashboard
1175. 质数排列 / 剑指 Offer II 104. 排列的数目
让企业数字化砸锅和IT主管背锅的软件供应链安全风险指北
Redis - understand the master-slave replication mechanism
2022-2028 global ethylene oxide scrubber industry research and trend analysis report
Plot size and resolution with R markdown, knitr, pandoc, beamer
What is the fastest way to import data from HDFS to Clickhouse? Spark is imported through JDBC or HDFS
Error when starting PHP: [pool www] cannot get uid for user '@php_ fpm_ [email protected]’