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