××redis××redisServerのdirtyメンバーの解読


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操作を実行するか否かを判断する.