Update Redis.md

重新绘制配图,补充 Lua 脚本、单线程模型、排行榜以及与 MySQL 的区别,更新持久化、复制和哨兵的描述。
This commit is contained in:
CyC2018
2026-10-26 22:03:57 +08:00
parent b4647213f8
commit 23ce787c54
29 changed files with 1179 additions and 122 deletions
+71
View File
@@ -0,0 +1,71 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="250" viewBox="0 0 760 250">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">AOF 重写:对 counter 执行 1000 次 INCR</text>
<text x="30" y="60" class="b">重写前</text>
<path d="M30,74 h37 l9,9 v49 h-46 z" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
<path d="M67,74 v9 h9" fill="none" stroke="#BBBBBB" stroke-width="1"/>
<line x1="36" y1="91" x2="69" y2="91" stroke="#BBBBBB" stroke-width="1"/>
<line x1="36" y1="98" x2="69" y2="98" stroke="#BBBBBB" stroke-width="1"/>
<line x1="36" y1="105" x2="69" y2="105" stroke="#BBBBBB" stroke-width="1"/>
<text x="90" y="88" class="sub mono" style="fill:#444">appendonly.aof.1.incr.aof</text>
<text x="90" y="106" class="sub">27023 字节,1000 条命令</text>
<rect x="90" y="116" width="250" height="96" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
<line x1="90" y1="130" x2="340" y2="130" stroke="#BBBBBB" stroke-width="1"/>
<circle cx="99" cy="123" r="2.2" fill="#BBBBBB"/>
<circle cx="107" cy="123" r="2.2" fill="#BBBBBB"/>
<circle cx="115" cy="123" r="2.2" fill="#BBBBBB"/>
<text x="99" y="146" class="sub mono">*2 $4 INCR $7 counter</text>
<text x="99" y="162" class="sub mono">*2 $4 INCR $7 counter</text>
<text x="99" y="178" class="sub mono">*2 $4 INCR $7 counter</text>
<text x="99" y="194" class="sub mono">……</text>
<line x1="360" y1="130" x2="420" y2="130" class="arrow "/>
<text x="390" y="120" class="c sub mono">BGREWRITEAOF</text>
<text x="390" y="148" class="c sub">子进程按当前数据</text>
<text x="390" y="164" class="c sub">重新生成</text>
<text x="440" y="60" class="b">重写后</text>
<path d="M440,74 h37 l9,9 v49 h-46 z" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<path d="M477,74 v9 h9" fill="none" stroke="#7FB2D6" stroke-width="1"/>
<line x1="446" y1="91" x2="479" y2="91" stroke="#7FB2D6" stroke-width="1"/>
<line x1="446" y1="98" x2="479" y2="98" stroke="#7FB2D6" stroke-width="1"/>
<line x1="446" y1="105" x2="479" y2="105" stroke="#7FB2D6" stroke-width="1"/>
<text x="500" y="92" class="sub mono" style="fill:#444">appendonly.aof.2.base.rdb</text>
<text x="500" y="110" class="sub">105 字节,RDB 格式:counter = 1000</text>
<path d="M440,146 h37 l9,9 v49 h-46 z" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
<path d="M477,146 v9 h9" fill="none" stroke="#BBBBBB" stroke-width="1"/>
<line x1="446" y1="163" x2="479" y2="163" stroke="#BBBBBB" stroke-width="1"/>
<line x1="446" y1="170" x2="479" y2="170" stroke="#BBBBBB" stroke-width="1"/>
<line x1="446" y1="177" x2="479" y2="177" stroke="#BBBBBB" stroke-width="1"/>
<text x="500" y="164" class="sub mono" style="fill:#444">appendonly.aof.2.incr.aof</text>
<text x="500" y="182" class="sub">0 字节,之后的写命令追加到这里</text>
<text x="30" y="238" class="sub">Redis 7.4 实测,文件在 appendonlydir 目录中,由 appendonly.aof.manifest 记录;aof-use-rdb-preamble 默认开启,基础文件用 RDB 格式。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

+63
View File
@@ -0,0 +1,63 @@
<svg xmlns="http://www.w3.org/2000/svg" width="560" height="220" viewBox="0 0 560 220">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="280" y="28" class="title">文章信息:一篇文章是一个 HASH</text>
<text x="30" y="86" class="sub b"></text>
<rect x="30" y="92" width="110" height="28" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="85" y="110" class="c sub mono" style="fill:#444">article:1001</text>
<text x="42" y="140" class="sub mono" style="fill:#296898">article</text>
<text x="42" y="156" class="sub">命名空间</text>
<text x="104" y="140" class="sub mono" style="fill:#296898">1001</text>
<text x="104" y="156" class="sub">ID</text>
<line x1="144" y1="106" x2="180" y2="106" class="arrow "/>
<rect x="184" y="46" width="80" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="224" y="62" class="c sub" style="fill:#444">字段</text>
<rect x="264" y="46" width="260" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="394" y="62" class="c sub" style="fill:#444">值</text>
<rect x="184" y="70" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="224" y="87" class="c sub mono" style="fill:#444">title</text>
<rect x="264" y="70" width="260" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="394" y="87" class="c sub" style="fill:#444">Redis 为什么快</text>
<rect x="184" y="96" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="224" y="113" class="c sub mono" style="fill:#444">author</text>
<rect x="264" y="96" width="260" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="394" y="113" class="c sub mono" style="fill:#444">user:2001</text>
<rect x="184" y="122" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="224" y="139" class="c sub mono" style="fill:#444">time</text>
<rect x="264" y="122" width="260" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="394" y="139" class="c sub" style="fill:#444">1760923800(2025-10-20 09:30)</text>
<rect x="184" y="148" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="224" y="165" class="c sub mono" style="fill:#444">votes</text>
<rect x="264" y="148" width="260" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="394" y="165" class="c sub mono" style="fill:#444">3</text>
<text x="30" y="202" class="sub">相当于关系型数据库中 article 表里 id = 1001 的一行。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

+71
View File
@@ -0,0 +1,71 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="300" viewBox="0 0 760 300">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">点赞:user:2004 给 article:1001 点赞</text>
<circle cx="50" cy="69" r="9" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<path d="M33,100 q0,-19 17,-19 q17,0 17,19 z" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="50" y="120" class="c sub mono">user:2004</text>
<line x1="76" y1="84" x2="126" y2="84" class="arrow "/>
<rect x="130" y="64" width="230" height="40" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="245" y="88.5" class="c sub mono">① SADD voted:1001 user:2004</text>
<path d="M245,106 V140 H160 V156" class="arrow green"/>
<text x="152" y="136" class="sub ok e">返回 1:第一次点赞</text>
<path d="M245,106 V140 H370 V156" class="arrow red"/>
<text x="260" y="136" class="sub note">返回 0:点过了</text>
<rect x="330" y="160" width="80" height="34" rx="6" fill="#F3C6C2" stroke="#BBBBBB"/>
<text x="370" y="181.5" class="c sub">拒绝</text>
<rect x="40" y="160" width="250" height="34" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="165" y="181.5" class="c sub mono">② HINCRBY article:1001 votes 1</text>
<text x="300" y="182" class="sub mono">→ 4</text>
<rect x="40" y="206" width="250" height="34" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="165" y="227.5" class="c sub mono">③ ZINCRBY votes: 1 article:1001</text>
<text x="300" y="228" class="sub mono">→ 4</text>
<line x1="160" y1="196" x2="160" y2="204" class="arrow "/>
<rect x="470" y="56" width="200" height="110" rx="5" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<rect x="470" y="56" width="200" height="22" rx="5" fill="#BFBEBA" opacity="0.35"/>
<text x="570" y="71" class="c b">voted:1001(SET)</text>
<rect x="476" y="84" width="188" height="16" rx="3" fill="#FFFFFF" stroke="#BFBEBA" stroke-width="0.6"/>
<text x="482" y="96" class="sub mono">user:2002</text>
<rect x="476" y="104" width="188" height="16" rx="3" fill="#FFFFFF" stroke="#BFBEBA" stroke-width="0.6"/>
<text x="482" y="116" class="sub mono">user:2003</text>
<rect x="476" y="124" width="188" height="16" rx="3" fill="#FFFFFF" stroke="#BFBEBA" stroke-width="0.6"/>
<text x="482" y="136" class="sub mono">user:2005</text>
<rect x="476" y="144" width="188" height="16" rx="3" fill="#E6E3FA" stroke="#BFBEBA" stroke-width="0.6"/>
<text x="482" y="156" class="sub mono">user:2004</text>
<text x="682" y="165" class="sub" style="fill:#766AA8">新增</text>
<circle cx="488" cy="198" r="10" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
<path d="M488,192 V198 L492.5,201" fill="none" stroke="#888" stroke-width="1.4" stroke-linecap="round"/>
<text x="504" y="202" class="sub">EXPIRE 604800:7 天后自动删除</text>
<text x="470" y="222" class="sub">超过一周不能再点赞,也不再占用内存</text>
<text x="30" y="270" class="sub">已点赞的用户记在集合里,SADD 的返回值说明这个用户是否点过,防止重复点赞。</text>
<text x="30" y="288" class="sub">三步可以放进一个 Lua 脚本中原子执行,避免只执行了一部分。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.6 KiB

+73
View File
@@ -0,0 +1,73 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="250" viewBox="0 0 760 250">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">排序:两个有序集合,成员都是文章 ID</text>
<text x="30" y="52" class="sub mono b" style="fill:#444">time:(分值是发布时间)</text>
<rect x="30" y="60" width="120" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="90" y="76" class="c sub" style="fill:#444">成员</text>
<rect x="150" y="60" width="110" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="205" y="76" class="c sub" style="fill:#444">分值</text>
<rect x="30" y="84" width="120" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="90" y="101" class="c sub mono" style="fill:#444">article:1001</text>
<rect x="150" y="84" width="110" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="205" y="101" class="c sub mono" style="fill:#444">1760923800</text>
<rect x="30" y="110" width="120" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="90" y="127" class="c sub mono" style="fill:#444">article:1002</text>
<rect x="150" y="110" width="110" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="205" y="127" class="c sub mono" style="fill:#444">1761026400</text>
<rect x="30" y="136" width="120" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="90" y="153" class="c sub mono" style="fill:#444">article:1003</text>
<rect x="150" y="136" width="110" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="205" y="153" class="c sub mono" style="fill:#444">1761135300</text>
<text x="30" y="186" class="sub mono" style="fill:#296898">ZRANGE time: 0 9 REV</text>
<text x="30" y="204" class="sub">最新的 10 篇:1003、1002、1001</text>
<text x="400" y="52" class="sub mono b" style="fill:#444">votes:(分值是点赞数)</text>
<rect x="400" y="60" width="120" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="460" y="76" class="c sub" style="fill:#444">成员</text>
<rect x="520" y="60" width="110" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="575" y="76" class="c sub" style="fill:#444">分值</text>
<rect x="400" y="84" width="120" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="460" y="101" class="c sub mono" style="fill:#444">article:1003</text>
<rect x="520" y="84" width="110" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="575" y="101" class="c sub mono" style="fill:#444">1</text>
<rect x="400" y="110" width="120" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="460" y="127" class="c sub mono" style="fill:#444">article:1001</text>
<rect x="520" y="110" width="110" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="575" y="127" class="c sub mono" style="fill:#444">4</text>
<rect x="400" y="136" width="120" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="460" y="153" class="c sub mono" style="fill:#444">article:1002</text>
<rect x="520" y="136" width="110" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="575" y="153" class="c sub mono" style="fill:#444">8</text>
<text x="400" y="186" class="sub mono" style="fill:#296898">ZRANGE votes: 0 9 REV</text>
<text x="400" y="204" class="sub">点赞最多的 10 篇:1002、1001、1003</text>
<text x="30" y="236" class="sub">有序集合按分值从小到大排列,REV 表示倒序取;取到文章 ID 后再用 HGETALL 读出每篇文章的信息。</text>
</svg>

After

Width:  |  Height:  |  Size: 5.2 KiB

+55
View File
@@ -0,0 +1,55 @@
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="330" viewBox="0 0 600 330">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="300" y="28" class="title">事件循环</text>
<rect x="230" y="46" width="140" height="34" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="300" y="67.5" class="c sub b">初始化服务器</text>
<rect x="200" y="104" width="200" height="34" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="300" y="125.5" class="c sub b">① 找到最近的时间事件</text>
<text x="412" y="126" class="sub">例如 serverCron 还有 30 ms 到期</text>
<rect x="200" y="154" width="200" height="34" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="300" y="175.5" class="c sub b">② epoll_wait 最多等待 30 ms</text>
<text x="412" y="176" class="sub">期间有文件事件就提前返回</text>
<line x1="300" y1="138" x2="300" y2="152" class="arrow "/>
<rect x="200" y="204" width="200" height="34" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="300" y="225.5" class="c sub b">③ 处理已就绪的文件事件</text>
<text x="412" y="226" class="sub">接受连接、执行命令、写回结果</text>
<line x1="300" y1="188" x2="300" y2="202" class="arrow "/>
<rect x="200" y="254" width="200" height="34" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="300" y="275.5" class="c sub b">④ 处理已到期的时间事件</text>
<text x="412" y="276" class="sub">serverCron 默认每 100 ms 执行一次</text>
<line x1="300" y1="238" x2="300" y2="252" class="arrow "/>
<line x1="300" y1="82" x2="300" y2="102" class="arrow "/>
<path d="M198,272 H160 V121 H196" class="arrow"/>
<text x="152" y="200" class="sub e">直到关闭</text>
<text x="30" y="316" class="sub">等待时间由最近的时间事件决定:既不会一直阻塞在 epoll_wait 上,也不会空转。</text>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

+84
View File
@@ -0,0 +1,84 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="290" viewBox="0 0 760 290">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">文件事件:一个线程处理多个客户端</text>
<rect x="40" y="60" width="40" height="27.2" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="44" y="64" width="32" height="19.2" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M56,87.2 v5 M64,87.2 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="48" y="92.2" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="60" y="110" class="c sub">客户端 A</text>
<line x1="86" y1="74" x2="186" y2="74" class="arrow"/>
<text x="136" y="66" class="c sub">新连接</text>
<rect x="40" y="124" width="40" height="27.2" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="44" y="128" width="32" height="19.2" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M56,151.2 v5 M64,151.2 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="48" y="156.2" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="60" y="174" class="c sub">客户端 B</text>
<line x1="86" y1="138" x2="186" y2="138" class="arrow"/>
<text x="136" y="130" class="c sub">发来 GET k</text>
<rect x="40" y="188" width="40" height="27.2" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="44" y="192" width="32" height="19.2" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M56,215.2 v5 M64,215.2 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="48" y="220.2" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="60" y="238" class="c sub">客户端 C</text>
<line x1="86" y1="202" x2="186" y2="202" class="arrow"/>
<text x="136" y="194" class="c sub">可以写回结果</text>
<rect x="192" y="66" width="130" height="150" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
<text x="257" y="132" class="c b">I/O 多路复用</text>
<text x="257" y="150" class="c sub mono">epoll_wait</text>
<text x="257" y="166" class="c sub">同时监听所有套接字</text>
<line x1="326" y1="141" x2="366" y2="141" class="arrow "/>
<rect x="370" y="128" width="120" height="26" rx="13" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
<rect x="380" y="132" width="30.6667" height="18" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="395.333" y="145" class="c sub">A</text>
<rect x="414.667" y="132" width="30.6667" height="18" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="430" y="145" class="c sub">B</text>
<rect x="449.333" y="132" width="30.6667" height="18" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="464.667" y="145" class="c sub">C</text>
<text x="430" y="118" class="c sub">就绪的事件</text>
<line x1="494" y1="141" x2="524" y2="141" class="arrow "/>
<rect x="528" y="116" width="56" height="50" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="556" y="145.5" class="c sub">分派</text>
<rect x="612" y="66" width="130" height="40" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="677" y="90.5" class="c sub b">连接应答处理器</text>
<text x="677" y="120" class="c sub">A:accept 新连接</text>
<line x1="588" y1="141" x2="608" y2="86" class="arrow "/>
<rect x="612" y="126" width="130" height="40" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="677" y="150.5" class="c sub b">命令请求处理器</text>
<text x="677" y="180" class="c sub">B:读出并执行 GET k</text>
<line x1="588" y1="141" x2="608" y2="146" class="arrow "/>
<rect x="612" y="186" width="130" height="40" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="677" y="210.5" class="c sub b">命令回复处理器</text>
<text x="677" y="240" class="c sub">C:把结果写给客户端</text>
<line x1="588" y1="141" x2="608" y2="206" class="arrow "/>
<text x="30" y="272" class="sub">执行命令的始终是一个线程:事件按顺序逐个处理,所以单条命令是原子的,但一条慢命令会阻塞其它客户端。</text>
</svg>

After

Width:  |  Height:  |  Size: 5.5 KiB

+57
View File
@@ -0,0 +1,57 @@
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="200" viewBox="0 0 480 200">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="240" y="28" class="title">HASH</text>
<text x="30" y="58" class="sub b"></text>
<rect x="30" y="64" width="100" height="28" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="80" y="82" class="c sub mono" style="fill:#444">user:1001</text>
<line x1="134" y1="78" x2="170" y2="78" class="arrow "/>
<rect x="174" y="50" width="90" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="219" y="66" class="c sub" style="fill:#444">字段</text>
<rect x="264" y="50" width="120" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="324" y="66" class="c sub" style="fill:#444">值</text>
<rect x="174" y="74" width="90" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="219" y="91" class="c sub mono" style="fill:#444">name</text>
<rect x="264" y="74" width="120" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="324" y="91" class="c sub mono" style="fill:#444">alice</text>
<rect x="174" y="100" width="90" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="219" y="117" class="c sub mono" style="fill:#444">age</text>
<rect x="264" y="100" width="120" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="324" y="117" class="c sub mono" style="fill:#444">25</text>
<rect x="174" y="126" width="90" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="219" y="143" class="c sub mono" style="fill:#444">city</text>
<rect x="264" y="126" width="120" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="324" y="143" class="c sub mono" style="fill:#444">hangzhou</text>
<text x="396" y="116" class="sub mono">HGET、HINCRBY</text>
<text x="396" y="132" class="sub">只读写一个字段</text>
<text x="30" y="186" class="sub">一个键下存放多个字段和值,适合存储对象,修改一个字段不用读出整个对象。</text>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

+59
View File
@@ -0,0 +1,59 @@
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="190" viewBox="0 0 480 190">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="240" y="28" class="title">LIST</text>
<text x="30" y="64" class="sub b"></text>
<rect x="30" y="70" width="120" height="28" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="90" y="88" class="c sub mono" style="fill:#444">orders:queue</text>
<line x1="154" y1="84" x2="184" y2="84" class="arrow "/>
<rect x="226" y="70" width="60" height="28" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="256" y="88" class="c sub mono" style="fill:#444">1024</text>
<text x="256" y="116" class="c sub mono">0</text>
<text x="256" y="132" class="c sub mono">-3</text>
<rect x="290" y="70" width="60" height="28" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="320" y="88" class="c sub mono" style="fill:#444">1025</text>
<text x="320" y="116" class="c sub mono">1</text>
<text x="320" y="132" class="c sub mono">-2</text>
<rect x="354" y="70" width="60" height="28" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="384" y="88" class="c sub mono" style="fill:#444">1026</text>
<text x="384" y="116" class="c sub mono">2</text>
<text x="384" y="132" class="c sub mono">-1</text>
<text x="216" y="116" class="sub e">下标</text>
<text x="216" y="132" class="sub e">负数下标</text>
<line x1="192" y1="78" x2="220" y2="78" class="arrow"/>
<line x1="220" y1="90" x2="192" y2="90" class="arrow"/>
<line x1="448" y1="78" x2="420" y2="78" class="arrow"/>
<line x1="420" y1="90" x2="448" y2="90" class="arrow"/>
<text x="206" y="62" class="c sub mono">LPUSH / LPOP</text>
<text x="434" y="62" class="c sub mono">RPUSH / RPOP</text>
<text x="30" y="168" class="sub">按插入顺序排列,元素可以重复;在两端插入和弹出是 O(1),按下标访问要从一端数过去。</text>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

+90
View File
@@ -0,0 +1,90 @@
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="300" viewBox="0 0 720 300">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="360" y="28" class="title">主从链:中间层分担复制</text>
<path d="M335,52 v34 a25,6 0 0 0 50,0 v-34" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
<ellipse cx="360" cy="52" rx="25" ry="6" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
<path d="M335,69 a25,6 0 0 0 50,0" fill="none" stroke="#7DBCB7" stroke-width="1"/>
<text x="400" y="74" class="sub b">主服务器</text>
<line x1="360" y1="96" x2="140" y2="136" class="arrow "/>
<path d="M118,146 v28 a22,6 0 0 0 44,0 v-28" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<ellipse cx="140" cy="146" rx="22" ry="6" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<path d="M118,160 a22,6 0 0 0 44,0" fill="none" stroke="#7FB2D6" stroke-width="1"/>
<text x="172" y="164" class="sub">从服务器 1</text>
<line x1="140" y1="184" x2="70" y2="222" class="arrow "/>
<path d="M53,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="70" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M53,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="140" y1="184" x2="140" y2="222" class="arrow "/>
<path d="M123,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="140" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M123,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="140" y1="184" x2="210" y2="222" class="arrow "/>
<path d="M193,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="210" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M193,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="360" y1="96" x2="360" y2="136" class="arrow "/>
<path d="M338,146 v28 a22,6 0 0 0 44,0 v-28" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<ellipse cx="360" cy="146" rx="22" ry="6" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<path d="M338,160 a22,6 0 0 0 44,0" fill="none" stroke="#7FB2D6" stroke-width="1"/>
<text x="392" y="164" class="sub">从服务器 2</text>
<line x1="360" y1="184" x2="290" y2="222" class="arrow "/>
<path d="M273,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="290" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M273,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="360" y1="184" x2="360" y2="222" class="arrow "/>
<path d="M343,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="360" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M343,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="360" y1="184" x2="430" y2="222" class="arrow "/>
<path d="M413,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="430" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M413,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="360" y1="96" x2="580" y2="136" class="arrow "/>
<path d="M558,146 v28 a22,6 0 0 0 44,0 v-28" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<ellipse cx="580" cy="146" rx="22" ry="6" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<path d="M558,160 a22,6 0 0 0 44,0" fill="none" stroke="#7FB2D6" stroke-width="1"/>
<text x="612" y="164" class="sub">从服务器 3</text>
<line x1="580" y1="184" x2="510" y2="222" class="arrow "/>
<path d="M493,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="510" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M493,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="580" y1="184" x2="580" y2="222" class="arrow "/>
<path d="M563,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="580" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M563,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<line x1="580" y1="184" x2="650" y2="222" class="arrow "/>
<path d="M633,232 v18 a17,6 0 0 0 34,0 v-18" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<ellipse cx="650" cy="232" rx="17" ry="6" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<path d="M633,241 a17,6 0 0 0 34,0" fill="none" stroke="#BFBEBA" stroke-width="1"/>
<text x="360" y="288" class="c sub">中间层既是上一层的从服务器,又是下一层的主服务器;主服务器只需向 3 台发送数据,而不是 12 台。</text>
</svg>

After

Width:  |  Height:  |  Size: 6.3 KiB

@@ -0,0 +1,76 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="330" viewBox="0 0 760 330">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">哨兵故障转移:kill -9 主服务器之后(本机实测)</text>
<line x1="60" y1="150" x2="720" y2="150" class="line"/>
<line x1="60" y1="150" x2="60" y2="155" stroke="#999"/>
<text x="60" y="170" class="c sub mono">0 s</text>
<line x1="160" y1="150" x2="160" y2="155" stroke="#999"/>
<text x="160" y="170" class="c sub mono">1 s</text>
<line x1="260" y1="150" x2="260" y2="155" stroke="#999"/>
<text x="260" y="170" class="c sub mono">2 s</text>
<line x1="360" y1="150" x2="360" y2="155" stroke="#999"/>
<text x="360" y="170" class="c sub mono">3 s</text>
<line x1="460" y1="150" x2="460" y2="155" stroke="#999"/>
<text x="460" y="170" class="c sub mono">4 s</text>
<line x1="560" y1="150" x2="560" y2="155" stroke="#999"/>
<text x="560" y="170" class="c sub mono">5 s</text>
<line x1="660" y1="150" x2="660" y2="155" stroke="#999"/>
<text x="660" y="170" class="c sub mono">6 s</text>
<rect x="60" y="140" width="504" height="20" rx="3" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="312" y="154" class="c sub" style="fill:#444">哨兵在 down-after-milliseconds(5 秒)内收不到回复</text>
<rect x="564" y="140" width="143" height="20" rx="3" fill="#E6E3FA" stroke="#B8B0DE"/>
<line x1="60" y1="140" x2="60" y2="126" stroke="#BBB" stroke-dasharray="2 2"/>
<circle cx="60" cy="150" r="3.5" fill="#C0605A"/>
<text x="64" y="120" class="sub" style="fill:#444">kill -9 主服务器 6400</text>
<line x1="564" y1="140" x2="564" y2="104" stroke="#BBB" stroke-dasharray="2 2"/>
<circle cx="564" cy="150" r="3.5" fill="#9F94D5"/>
<text x="560" y="98" class="sub e" style="fill:#444">5.04 s ① 主观下线 +sdown</text>
<line x1="574" y1="140" x2="574" y2="82" stroke="#BBB" stroke-dasharray="2 2"/>
<circle cx="574" cy="150" r="3.5" fill="#9F94D5"/>
<text x="570" y="76" class="sub e" style="fill:#444">5.14 s ② 客观下线 +odown,3 个哨兵都同意(quorum 2)</text>
<line x1="582" y1="160" x2="582" y2="182" stroke="#BBB" stroke-dasharray="2 2"/>
<circle cx="582" cy="150" r="3.5" fill="#9F94D5"/>
<text x="578" y="194" class="sub e" style="fill:#444">5.22 s ③ 投票选出领头哨兵 +elected-leader</text>
<line x1="588" y1="160" x2="588" y2="204" stroke="#BBB" stroke-dasharray="2 2"/>
<circle cx="588" cy="150" r="3.5" fill="#9F94D5"/>
<text x="584" y="216" class="sub e" style="fill:#444">5.28 s ④ 选中 6402 +selected-slave</text>
<line x1="697" y1="160" x2="697" y2="226" stroke="#BBB" stroke-dasharray="2 2"/>
<circle cx="697" cy="150" r="3.5" fill="#9F94D5"/>
<text x="693" y="238" class="sub e" style="fill:#444">6.37 s ⑤ 6402 升为主服务器 +promoted-slave</text>
<line x1="707" y1="160" x2="707" y2="248" stroke="#BBB" stroke-dasharray="2 2"/>
<circle cx="707" cy="150" r="3.5" fill="#9F94D5"/>
<text x="703" y="260" class="sub e" style="fill:#444">6.47 s ⑥ 通知切换 +switch-master</text>
<text x="30" y="286" class="sub">1 主 2 从、3 个哨兵,quorum 为 2。约 6.5 秒后客户端从哨兵查到新地址 6402,之前写入的 order:1024 仍在;</text>
<text x="30" y="304" class="sub">重启的 6400 被哨兵改为 6402 的从服务器。超时检测占了大部分时间,down-after-milliseconds 越小切换越快,</text>
<text x="30" y="322" class="sub">但网络抖动时也越容易误判。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

+45
View File
@@ -0,0 +1,45 @@
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="220" viewBox="0 0 480 220">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="240" y="28" class="title">SET</text>
<ellipse cx="220" cy="126" rx="92" ry="58" fill="#C6E4FB" fill-opacity="0.75" stroke="#7FB2D6"/>
<ellipse cx="330" cy="126" rx="80" ry="50" fill="#C6ECE9" fill-opacity="0.75" stroke="#7DBCB7"/>
<text x="170" y="114" class="c sub mono" style="fill:#444">cache</text>
<text x="178" y="144" class="c sub mono" style="fill:#444">nosql</text>
<text x="272" y="130" class="c sub mono b" style="fill:#444">redis</text>
<text x="360" y="130" class="c sub mono" style="fill:#444">mysql</text>
<text x="180" y="60" class="c sub mono" style="fill:#444">article:7:tags</text>
<text x="370" y="70" class="c sub mono" style="fill:#444">article:8:tags</text>
<text x="272" y="206" class="c sub" style="fill:#296898">SINTER 得到交集 redis</text>
<text x="30" y="116" class="sub">元素不重复,</text>
<text x="30" y="132" class="sub">没有顺序</text>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

+104
View File
@@ -0,0 +1,104 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="300" viewBox="0 0 760 300">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">跳跃表:查找 26</text>
<text x="30" y="111" class="sub">第 2 层</text>
<rect x="88" y="93" width="44" height="26" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="110" y="111" class="c sub mono" style="fill:#444">head</text>
<line x1="132" y1="106" x2="348" y2="106" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="384" y1="106" x2="604" y2="106" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<rect x="348" y="93" width="36" height="26" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="366" y="111" class="c sub mono" style="fill:#444">15</text>
<rect x="604" y="93" width="36" height="26" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="622" y="111" class="c sub mono" style="fill:#444">30</text>
<line x1="366" y1="119" x2="366" y2="145" stroke="#DDD" stroke-width="1"/>
<line x1="622" y1="119" x2="622" y2="145" stroke="#DDD" stroke-width="1"/>
<text x="30" y="163" class="sub">第 1 层</text>
<rect x="88" y="145" width="44" height="26" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="110" y="163" class="c sub mono" style="fill:#444">head</text>
<line x1="132" y1="158" x2="220" y2="158" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="256" y1="158" x2="348" y2="158" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="384" y1="158" x2="476" y2="158" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="512" y1="158" x2="604" y2="158" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<rect x="220" y="145" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="238" y="163" class="c sub mono" style="fill:#444">7</text>
<rect x="348" y="145" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="366" y="163" class="c sub mono" style="fill:#444">15</text>
<rect x="476" y="145" width="36" height="26" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="494" y="163" class="c sub mono" style="fill:#444">22</text>
<rect x="604" y="145" width="36" height="26" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="622" y="163" class="c sub mono" style="fill:#444">30</text>
<line x1="238" y1="171" x2="238" y2="197" stroke="#DDD" stroke-width="1"/>
<line x1="366" y1="171" x2="366" y2="197" stroke="#DDD" stroke-width="1"/>
<line x1="494" y1="171" x2="494" y2="197" stroke="#DDD" stroke-width="1"/>
<line x1="622" y1="171" x2="622" y2="197" stroke="#DDD" stroke-width="1"/>
<text x="30" y="215" class="sub">第 0 层</text>
<rect x="88" y="197" width="44" height="26" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="110" y="215" class="c sub mono" style="fill:#444">head</text>
<line x1="132" y1="210" x2="156" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="192" y1="210" x2="220" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="256" y1="210" x2="284" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="320" y1="210" x2="348" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="384" y1="210" x2="412" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="448" y1="210" x2="476" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="512" y1="210" x2="540" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="576" y1="210" x2="604" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<line x1="640" y1="210" x2="668" y2="210" stroke="#AAA" stroke-width="1.1" marker-end="url(#a)"/>
<rect x="156" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="174" y="215" class="c sub mono" style="fill:#444">3</text>
<rect x="220" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="238" y="215" class="c sub mono" style="fill:#444">7</text>
<rect x="284" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="302" y="215" class="c sub mono" style="fill:#444">11</text>
<rect x="348" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="366" y="215" class="c sub mono" style="fill:#444">15</text>
<rect x="412" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="430" y="215" class="c sub mono" style="fill:#444">19</text>
<rect x="476" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="494" y="215" class="c sub mono" style="fill:#444">22</text>
<rect x="540" y="197" width="36" height="26" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
<text x="558" y="215" class="c sub mono" style="fill:#444">26</text>
<rect x="604" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="622" y="215" class="c sub mono" style="fill:#444">30</text>
<rect x="668" y="197" width="36" height="26" rx="4" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="686" y="215" class="c sub mono" style="fill:#444">37</text>
<path d="M128,86 H348" class="arrow red"/>
<path d="M340,112 V150" class="arrow red"/>
<path d="M384,138 H476" class="arrow red"/>
<path d="M468,164 V202" class="arrow red"/>
<path d="M512,190 H540" class="arrow red"/>
<text x="622" y="82" class="c sub note">30 &gt; 26,下降</text>
<text x="676" y="134" class="c sub note">30 &gt; 26,下降</text>
<text x="558" y="244" class="c sub note">找到</text>
<text x="30" y="270" class="sub">从最高层出发,下一个节点小于 26 就向右走,大于 26 就下降一层。</text>
<text x="30" y="288" class="sub">共比较 5 次(15、30、22、30、26);在最底层的链表中逐个查找要比较 7 次,节点越多差距越大。</text>
</svg>

After

Width:  |  Height:  |  Size: 7.5 KiB

+49
View File
@@ -0,0 +1,49 @@
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="180" viewBox="0 0 480 180">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="240" y="28" class="title">STRING</text>
<text x="30" y="56" class="sub b"></text>
<rect x="30" y="62" width="140" height="28" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="100" y="80" class="c sub mono" style="fill:#444">user:1001:name</text>
<line x1="174" y1="76" x2="214" y2="76" class="arrow "/>
<rect x="218" y="62" width="90" height="28" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="263" y="80" class="c sub mono" style="fill:#444">alice</text>
<text x="320" y="80" class="sub">字符串</text>
<text x="30" y="110" class="sub b"></text>
<rect x="30" y="116" width="140" height="28" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="100" y="134" class="c sub mono" style="fill:#444">page:views</text>
<line x1="174" y1="130" x2="214" y2="130" class="arrow "/>
<rect x="218" y="116" width="90" height="28" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="263" y="134" class="c sub mono" style="fill:#444">42</text>
<text x="320" y="134" class="sub">整数,可以 INCR 自增</text>
<text x="30" y="168" class="sub">一个键对应一个值,值可以是字符串、整数或浮点数,最大 512 MB。</text>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

+62
View File
@@ -0,0 +1,62 @@
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="210" viewBox="0 0 480 210">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="240" y="28" class="title">ZSET</text>
<text x="30" y="58" class="sub b"></text>
<rect x="30" y="64" width="100" height="28" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="80" y="82" class="c sub mono" style="fill:#444">rank:score</text>
<line x1="134" y1="78" x2="170" y2="78" class="arrow "/>
<rect x="174" y="50" width="80" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="214" y="66" class="c sub" style="fill:#444">成员</text>
<rect x="254" y="50" width="60" height="24" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="284" y="66" class="c sub" style="fill:#444">分值</text>
<rect x="174" y="74" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="214" y="91" class="c sub mono" style="fill:#444">bob</text>
<rect x="254" y="74" width="60" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="284" y="91" class="c sub mono" style="fill:#444">85</text>
<rect x="324" y="81" width="60" height="12" rx="2" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="390" y="91" class="sub">名次 0</text>
<rect x="174" y="100" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="214" y="117" class="c sub mono" style="fill:#444">alice</text>
<rect x="254" y="100" width="60" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="284" y="117" class="c sub mono" style="fill:#444">92</text>
<rect x="324" y="107" width="88" height="12" rx="2" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="418" y="117" class="sub">名次 1</text>
<rect x="174" y="126" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="214" y="143" class="c sub mono" style="fill:#444">carol</text>
<rect x="254" y="126" width="60" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="284" y="143" class="c sub mono" style="fill:#444">97</text>
<rect x="324" y="133" width="108" height="12" rx="2" fill="#9F94D5" stroke="#BBBBBB" stroke-width="1"/>
<text x="438" y="143" class="sub">名次 2</text>
<text x="174" y="172" class="sub">按分值从小到大排列,名次从 0 开始</text>
<text x="30" y="196" class="sub">成员不重复,每个成员带一个分值;可以按名次或分值范围查询,适合排行榜。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.0 KiB