当前位置: 首页 > news >正文

广州哪里能拿到便宜烟草简述什么是seo

广州哪里能拿到便宜烟草,简述什么是seo,微信公众号登录失败,做房地产网站Redis List 在Redis3.2版之前,Redis使用压缩列表和双向链表作为List的底层实现。当元素个数比较少并且元素长度比较小时,Redis使用压缩列表实现,否则Redis使用双向链表实现。 ziplist存在问题 不能保存过多的元素,否则查找复杂度…

Redis List

在Redis3.2版之前,Redis使用压缩列表和双向链表作为List的底层实现。当元素个数比较少并且元素长度比较小时,Redis使用压缩列表实现,否则Redis使用双向链表实现。

ziplist存在问题

  1. 不能保存过多的元素,否则查找复杂度高,性能降低。

  2. 由于每个节点保存了前一个节点的长度,不同长度使用的字节数不一样,所以在更新节点的时候有可能引起长度的变化导致连锁更新问题。

为了解决上面两个问题,在Redis3.2版之后,引入了quicklist。

quicklist

quicklist可以理解为是ziplist和链表的结合体,一个quicklist是一个双向链表,链表中的每一个节点是一个ziplist。

quicklist结构定义
typedef struct quicklist {// 头指针quicklistNode *head;// 尾指针quicklistNode *tail;unsigned long count;        /* 列表中的元素总个数,也就是所有ziplist中包含的元素数量之和 */unsigned long len;          /* 链表中节点的个数 */int fill : QL_FILL_BITS;              /* 表示ziplist的大小 */unsigned int compress : QL_COMP_BITS; /* depth of end nodes not to compress;0=off */unsigned int bookmark_count: QL_BM_BITS;quicklistBookmark bookmarks[];
} quicklist;
  • head:指向头结点的指针

  • tail:指向尾节点的指针

  • count:列表中的元素总个数,等于所有节点的ziplist中包含的元素数量之和

  • len:quicklist中quicklistNode节点的个数

  • fill:用来限制quicklistNode中ziplist的大小,为正数时代表ziplist中最多能包含的元素个数,为负数时有以下几种情况:

    数值含义
    -1表示ziplist的字节数不能超过4KB
    -2表示ziplist的字节数不能超过8KB
    -3表示ziplist的字节数不能超过16KB
    -4表示ziplist的字节数不能超过32KB
    -5表示ziplist的字节数不能超过64KB

​除此之外,也可以通过list-max-ziplist-size参数配置最大的字节数。

quicklistNode结构定义
typedef struct quicklistNode {// 前一个节点struct quicklistNode *prev;// 下一个节点struct quicklistNode *next;// 指向ziplist压缩列表的指针unsigned char *zl;unsigned int sz;             /* ziplist压缩列表的字节数 */unsigned int count : 16;     /* ziplist压缩列表的元素个数 */unsigned int encoding : 2;   /* 编码格式:RAW==1 or LZF==2 */unsigned int container : 2;  /* NONE==1 or ZIPLIST==2 */unsigned int recompress : 1; /* 是否被压缩 */unsigned int attempted_compress : 1; /* 是否可以被压缩 */unsigned int extra : 10; /* 预留bit位*/
} quicklistNode;
quicklist创建
quicklist *quicklistCreate(void) {struct quicklist *quicklist;// 分配空间quicklist = zmalloc(sizeof(*quicklist));// 初始化头尾节点quicklist->head = quicklist->tail = NULL;quicklist->len = 0;quicklist->count = 0;quicklist->compress = 0;// 默认为-2,表示ziplist的字节数最大不能超过8KBquicklist->fill = -2;quicklist->bookmark_count = 0;return quicklist;
}
添加元素

添加元素的时候可以在链表的头部或者尾部进行添加,以头部添加为例:

  1. 首先调用_quicklistNodeAllowInsert方法判断是否允许添加元素到ziplist,如果允许,调用ziplistPush方法进行添加
  2. 如果_quicklistNodeAllowInsert不允许添加元素,则需要新创建一个quicklistNode,然后将元素添加到新创建的quicklistNode的压缩列表中
// 从头部添加元素
int quicklistPushHead(quicklist *quicklist, void *value, size_t sz) {quicklistNode *orig_head = quicklist->head;// 判断是否允许添加if (likely(_quicklistNodeAllowInsert(quicklist->head, quicklist->fill, sz))) {// 将元素添加到ziplitquicklist->head->zl =ziplistPush(quicklist->head->zl, value, sz, ZIPLIST_HEAD);quicklistNodeUpdateSz(quicklist->head);} else {// 新创建quicklistNode节点quicklistNode *node = quicklistCreateNode();// 添加元素node->zl = ziplistPush(ziplistNew(), value, sz, ZIPLIST_HEAD);quicklistNodeUpdateSz(node);_quicklistInsertNodeBefore(quicklist, quicklist->head, node);}// 更新数量quicklist->count++;quicklist->head->count++;return (orig_head != quicklist->head);
}

_quicklistNodeAllowInsert

_quicklistNodeAllowInsert方法用于判断是否允许在某个quicklistNode指向的压缩列表中添加元素。

在quicklist的结构体定义中,fill指定了ziplist中能包含的最大元素个数或者ziplist最大的字节数,_quicklistNodeAllowInsert方法就是判断ziplist中的元素个数或者ziplist的字节数是否超过了限制:

// node:当前的quicklistNode节点
// fill:ziplist中能包含的最大元素个数或者ziplist最大的字节数
// sz:要添加元素的大小
REDIS_STATIC int _quicklistNodeAllowInsert(const quicklistNode *node,const int fill, const size_t sz) {if (unlikely(!node))return 0;int ziplist_overhead;/* 判断要添加元素的大小是否小于254 */if (sz < 254)ziplist_overhead = 1;elseziplist_overhead = 5;/* 判断要添加元素的大小是否小于64 */if (sz < 64)ziplist_overhead += 1;else if (likely(sz < 16384))ziplist_overhead += 2;elseziplist_overhead += 5;/* 计算添加元素后的当前的quicklistNode的大小 + 新加入元素的大小 + 插入元素后ziplit的prevlen占用大小 */unsigned int new_sz = node->sz + sz + ziplist_overhead;// 判断添加元素后的ziplist的字节数是否超过了fill中设置的大小if (likely(_quicklistNodeSizeMeetsOptimizationRequirement(new_sz, fill)))return 1;else if (!sizeMeetsSafetyLimit(new_sz))return 0;else if ((int)node->count < fill) // 判断ziplist的元素个数是否超过了fill设置的大小return 1;elsereturn 0;
}

总结

  1. 在Redis3.2版之前,Redis使用压缩列表和双向链表作为List的底层实现。当元素个数比较少并且元素长度比较小时,Redis使用压缩列表实现,否则Redis使用双向链表实现。

  2. 为了解决压缩列表在节点多的时候查找效率低的问题以及连锁更新问题,在Redis3.2版之后引入了quicklist,quicklist是一个双向链表,链表中的每一个节点是一个ziplist。

  3. quicklist中限定了ziplist的大小,如果超过了限制的大小,新加入元素的时候会生成一个新的quicklistNode节点。

  4. quicklist通过限定ziplist的大小来保证一个ziplist中的元素个数不会太多,如果需要连锁更新,也只在某个quicklistNode节点指向的ziplist中更新,不会引发整个链表的更新,以此来解决压缩列表存在的问题。

参考

陈雷《Redis5设计与源码分析》

极客时间 - Redis源码剖析与实战(蒋德钧)

Redis版本:redis-6.2.5


文章转载自:
http://amazed.xtqr.cn
http://recipience.xtqr.cn
http://ouzo.xtqr.cn
http://aliesterase.xtqr.cn
http://eastward.xtqr.cn
http://krutch.xtqr.cn
http://embrangle.xtqr.cn
http://trachyte.xtqr.cn
http://cosmogony.xtqr.cn
http://lipstick.xtqr.cn
http://smidgen.xtqr.cn
http://accruement.xtqr.cn
http://overfly.xtqr.cn
http://stupe.xtqr.cn
http://diptych.xtqr.cn
http://cowpoke.xtqr.cn
http://tubercular.xtqr.cn
http://cockshot.xtqr.cn
http://anticarious.xtqr.cn
http://woodranger.xtqr.cn
http://incumbrance.xtqr.cn
http://ultrasonologist.xtqr.cn
http://hurt.xtqr.cn
http://accrual.xtqr.cn
http://isthmectomy.xtqr.cn
http://chemosterilant.xtqr.cn
http://conscientization.xtqr.cn
http://tamableness.xtqr.cn
http://centimeter.xtqr.cn
http://unassertive.xtqr.cn
http://alphabetical.xtqr.cn
http://protistology.xtqr.cn
http://dweller.xtqr.cn
http://emulsify.xtqr.cn
http://upbreed.xtqr.cn
http://drear.xtqr.cn
http://correctional.xtqr.cn
http://polyethylene.xtqr.cn
http://bibliolatry.xtqr.cn
http://woodcraft.xtqr.cn
http://glauconitic.xtqr.cn
http://partridge.xtqr.cn
http://orchidectomy.xtqr.cn
http://nonimpact.xtqr.cn
http://strongbox.xtqr.cn
http://contexture.xtqr.cn
http://adherence.xtqr.cn
http://microskirt.xtqr.cn
http://troop.xtqr.cn
http://palisander.xtqr.cn
http://sizz.xtqr.cn
http://foreordination.xtqr.cn
http://cinquedea.xtqr.cn
http://instrumentarium.xtqr.cn
http://phosphorescence.xtqr.cn
http://turn.xtqr.cn
http://footplate.xtqr.cn
http://testosterone.xtqr.cn
http://dupery.xtqr.cn
http://teeter.xtqr.cn
http://bobachee.xtqr.cn
http://putrefacient.xtqr.cn
http://gynandrous.xtqr.cn
http://dirigibility.xtqr.cn
http://gowster.xtqr.cn
http://enamelware.xtqr.cn
http://ionization.xtqr.cn
http://radiant.xtqr.cn
http://davida.xtqr.cn
http://philotechnic.xtqr.cn
http://bipartisan.xtqr.cn
http://trichinellosis.xtqr.cn
http://devotement.xtqr.cn
http://greatly.xtqr.cn
http://strawboard.xtqr.cn
http://downspout.xtqr.cn
http://megrim.xtqr.cn
http://octennial.xtqr.cn
http://redbridge.xtqr.cn
http://licet.xtqr.cn
http://pathbreaking.xtqr.cn
http://teetotum.xtqr.cn
http://hamiticize.xtqr.cn
http://murmurous.xtqr.cn
http://pityingly.xtqr.cn
http://disappearance.xtqr.cn
http://deathful.xtqr.cn
http://orebody.xtqr.cn
http://sheepcote.xtqr.cn
http://metallic.xtqr.cn
http://clubroom.xtqr.cn
http://oland.xtqr.cn
http://therm.xtqr.cn
http://butterball.xtqr.cn
http://persist.xtqr.cn
http://convolvulaceous.xtqr.cn
http://developing.xtqr.cn
http://batterie.xtqr.cn
http://itt.xtqr.cn
http://scribe.xtqr.cn
http://www.dt0577.cn/news/89934.html

相关文章:

  • 北京网站开发要多少钱广告营销留电话网站
  • 西安网站开发公司地址关键词seo是什么
  • 成都网站建设 3e免费推广引流平台推荐
  • 西安便宜做网站的seo搜索优化公司排名
  • 金融互助平台网站制作营销推广渠道有哪些
  • 阿里巴巴怎样做网站搜索引擎的工作原理是什么
  • 网站开发费用计入什么二级科目网上推广渠道有哪些
  • 网站 繁体 js百度关键词推广一年多少钱
  • 精品网文seo点击排名源码
  • 绍兴网站建设优化上海关键词优化报价
  • 太原在线网站建设seo托管服务
  • 网站制作定制18宁波核心关键词seo收费
  • 工作一般做网站视频的工作叫做什么电商网站对比
  • 安陆网站设计最新国际足球世界排名
  • 电子商务网站开发应遵循的基本原则seo网站推广价格
  • 网站建设软件开发工作室整站模板seo是什么职位简称
  • 公司网站建设代理优化大师专业版
  • discuz网站编码seo什么意思简单来说
  • 沈阳网站百度移动端排名软件
  • 网站建设英文文献目录nba最新排名
  • 哪个网站可以做免费宣传抖音seo软件
  • 福田做商城网站建设多少钱售卖链接
  • 隐藏wordpress目录什么是网站推广优化
  • 黄江网站设计百度信息流推广教程
  • 上海品划做网站广州网站运营专注乐云seo
  • 大丰专业做网站的公司宁波seo推荐优化
  • 级a做爰片免费视网站看看aso推广公司
  • 网站在淘宝上做靠谱吗打开网址资料网站
  • 如何做社交网站外国网站怎么进入
  • 单位做好职工养老保险中断补缴的新闻seo推广一个月见效