2.3.redis-写数据流程概述

set command流程概述

  • 流程调用以redis5.0版本为例,set command流程(倒序调用debug偷懒)如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
dictAddRaw dict.c:317
//处理渐进hash,获取索引,选用ht,存储ht->table
dictAdd dict.c:267
//代码较为简单,调用dictAddRaw,设置val
dbAdd db.c:175
//调用dictAdd,处理集群slotToKeyAdd
setKey db.c:218
//决定为dbadd or dboverwrite,计数器自增,删除过期key,key通知
setGenericCommand t_string.c:86
//调用setKey【数据类型】
setCommand t_string.c:139
//调用setGenericCommand【数据类型】
call server.c:2478
//进行计时调用,c->cmd->proc(c);分发执行调用setCommand,进行慢查询日志记录,只记录大于配置时间的
processCommand server.c:2785
//处理特殊命令,命令分类及执行方式,如是否要加入队列
processInputBuffer networking.c:1466
//调用processCommand
processInputBufferAndReplicate networking.c:1501
//任务分发
readQueryFromClient networking.c:1583
//
aeProcessEvents ae.c:443
//数据转发
aeMain ae.c:501
//处理网络事件
main server.c:4437
//传入server调用事件
start 0x00007fff6957ecc9

hset流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
dictAddRaw dict.c:298
dictAdd dict.c:267
dbAdd db.c:175
hashTypeLookupWriteOrCreate t_hash.c:455
hsetnxCommand t_hash.c:516
call server.c:2478
//信令查询进行分发
processCommand server.c:2785
processInputBuffer networking.c:1466
processInputBufferAndReplicate networking.c:1501
readQueryFromClient networking.c:1583
aeProcessEvents ae.c:443
aeMain ae.c:501
main server.c:4437
start 0x00007fff6957ecc9