主要是挖个坑。候补(代码还没看完。。)
https://github.com/antirez/redis/tree/5.0
一、Redis保存持久化文件
二、Redis启动加载持久化文件
src/server.c loadDataFromDisk函数 AOF 和 RDB 通过不同的方式加载
1 /* Function called at startup to load RDB or AOF file in memory. */ 2 void loadDataFromDisk(void) { 3 long long start = ustime(); 4 if (server.aof_state == AOF_ON) { 5 if (loadAppendOnlyFile(server.aof_filename) == C_OK) 6 serverLog(LL_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000); 7 } else { 8 rdbSaveInfo rsi = RDB_SAVE_INFO_INIT; 9 if (rdbLoad(server.rdb_filename,&rsi) == C_OK) { 10 serverLog(LL_NOTICE,"DB loaded from disk: %.3f seconds", 11 (float)(ustime()-start)/1000000); 12 13 /* Restore the replication ID / offset from the RDB file. */ 14 if (server.masterhost && 15 rsi.repl_id_is_set && 16 rsi.repl_offset != -1 && 17 /* Note that older implementations may save a repl_stream_db 18 * of -1 inside the RDB file in a wrong way, see more information 19 * in function rdbPopulateSaveInfo. */ 20 rsi.repl_stream_db != -1) 21 { 22 memcpy(server.replid,rsi.repl_id,sizeof(server.replid)); 23 server.master_repl_offset = rsi.repl_offset; 24 /* If we are a slave, create a cached master from this 25 * information, in order to allow partial resynchronizations 26 * with masters. */ 27 replicationCacheMasterUsingMyself(); 28 selectDb(server.cached_master,rsi.repl_stream_db); 29 } 30 } else if (errno != ENOENT) { 31 serverLog(LL_WARNING,"Fatal error loading the DB: %s. Exiting.",strerror(errno)); 32 exit(1); 33 } 34 } 35 }