从版本 1.1 >
xu yang编辑
在2022/04/27 12:12上
到版本
xu yang编辑
在2022/04/27 12:45上
>
修改评论 该版本没有评论

Summary

Details

Page properties
Content
... ... @@ -1,10 +1,12 @@
1 +get命令本质是调用了lookupKeyRead这个底层方法,
2 +lookupKeyRead方法如下:
3 +
1 1  {{plantuml}}
2 2  @startuml
3 3  start
4 4  
5 -:GET Command;
6 6  
7 -: lookupKeyRead();
9 +: lookupKeyReadWithFlags;
8 8  
9 9  
10 10  end
... ... @@ -11,15 +11,77 @@
11 11  @enduml
12 12  {{/plantuml}}
13 13  
16 +
17 +lookupKeyReadWithFlags方法如下:
18 +
14 14  {{plantuml}}
15 15  @startuml
16 16  start
17 17  
18 -:lookupKeyRead();
23 +if(调用expireIfNeeded方法判断key是否过期)then(1:代表过期)
24 +if(当前环境为主节点)then(yes)
25 +:返回null;
26 +stop
27 +endif
19 19  
20 -: lookupKeyReadWithFlags();
29 +if(当前环境为从节点,并且命令为读的时候,那说明key过期是安全的)then(yes)
30 +:返回null;
31 +stop
32 +endif
33 +endif
21 21  
35 +:调用lookupKey方法,查询value的值;
36 +if(返回值为空)then(yes)
37 +:缓存命中+1;
38 +else(no)
39 +:缓存非命中+1;
40 +endif
22 22  
42 +:返回查询的结果;
43 +
23 23  end
24 24  @enduml
25 25  {{/plantuml}}
47 +
48 +
49 +expireIfNeeded方法用来判断一个key是否过期
50 +返回1,说明已经过期
51 +返回0,说明数据没有过期
52 +
53 +{{plantuml}}
54 +@startuml
55 +start
56 +
57 +
58 +:查询key的过期时间戳;
59 +:获取当前时刻的时间戳;
60 +if(过期时间<0)then(yes)
61 +:说明该key不存在过期设置,返回0;
62 +stop
63 +endif
64 +
65 +if(服务器正在启动中)then(yes)
66 +:过期时间表可能没加载完全,这时直接返回0;
67 +stop
68 +endif
69 +
70 +if(当前环境是从服务器)then(yes)
71 +:对于从服务器无需删除过期key, 直接计算过期时间和当前时间的关系并返回;
72 +note left
73 +过期时间 <= 当前时间 : 已经过期
74 +过期时间 > 当前时间 : 没有过期
75 +stop
76 +endif
77 +
78 +:写aof删除过期key;
79 +:创建消息通知,用来回调那些监控key过期的钩子;
80 +if(判断服务器是否打开惰性删除)then(yes)
81 +:调用dbAsyncDelete方法异步删除;
82 +else(no)
83 +:调用dbSyncDelete方法同步删除;
84 +endif
85 +
86 +
87 +end
88 +@enduml
89 +{{/plantuml}}