Redis sorted set source code analysis

Source: Internet
Author: User
Sorted set in t_zset.c file.

Insert operation: Zaddcommand -----> detail {zzlfind {detail {zzlinsert -------- {ziplist: http://blog.nosqlfan.com/html/3919.html -------- {zzlgetscore -------- {zzlinsertat detail {ziplistpush detail {ziplistinsert {dictadd {dictfind {dictgetkey {dictgetval {response: zskiplist insert ------------: http://www.cnblogs.com/xuqiang/archive/2011/05/22/2053516.html {zsetconvert: If the element is too large or the list becomes too long executing zzlinsert ------------ {dictcreate -------------- {zslcreate
######################################## ##################### ARGs: @ Zs-> dict: -------------: Zs -----> zset struct @ ele-> redisobject @ & znode-> score @ elements: add element number @ redisobject: http://tech.it168.com/a2011/0818/1234/000001234478_all.shtml@ zobj is redisobject -------- zobj-> encoding is the type of sort set key
######################################## ##################### Program process: 1. parsing all the scores2. lookup the key exist? ---- If not exist -------- if has not ziplist or ziplist value <Len ------------ creatzsetobject -------- else createzsetziplistobject -------- dbadd key3. Insert the key ---- for insert all element ---- if the node is less the max- ziplist-entries or node value less max-ziplist-value -------- use ziplist struct -------- else use skiplist ---- else if the key already encoding in redis_encoding_skinglist -------- Insert the node in skiplist and dict ### ######################################## ################### summary: 1. the time complexity is log (n) because of skiplist2. the time of dict is 0 (1 ). use mapping like: Key ----> score
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.