××redis××redisServer中dirty成员解读

来源:互联网 发布:java如何实现内部链表 编辑:程序博客网 时间:2024/05/22 05:19
struct redisServer {//...    long long dirty;            /* changes to DB from the last save */    long long dirty_before_bgsave; /* used to restore dirty on failed BGSAVE *///...};

如注释所言,redisServer中的dirty用来存储上次保存前所有数据变动的长度。


dirty将在如下情况被累加:

update

flush

delete

rename command

move command

expire command

persist command

exec command

script command

sort command

set系列命令: hset hsetnx hmset hincrby hdel

list系列命令:push pushx lset pop

command

...


dirty将在如下情况被削减:

rdbsave后减去rdb所存储的数据的长度


dirty将在如下情况被重新设置为0:

在initServer中被初始化为零

执行debug command

执行rdb存储


diry在aof中的一个应用:

在call函数中:

void call(redisClient *c) {   //...    dirty = server->dirty;    c->cmd->proc(c);    dirty = server->dirty-dirty;//...    if (server->appendonly && dirty > 0) { //...         len = feedAppendOnlyFile(c->cmd,c->db->id,c->argv,c->argc);//...                       }   }



会通过如上步骤来判断在执行命令的过程中是否有了db中数据的变化,用得到的结果来判断要不要执行aof操作。

0 0
原创粉丝点击