Redis 源碼分析 - 復制
阿新 • • 發佈:2017-07-04
cancel ons sync set res server mas psync 結點
Redis 復制源碼:
Simple Dynamic String
使用復制功能,需要設置主備結點,下面的是設置Master結點的代碼。
需要指定Master結點的IP地址與Port端口號。
這裏
/* Set replication to the specified master address and port. */ void replicationSetMaster(char *ip, int port) { sdsfree(server.masterhost); server.masterhost = sdsnew(ip); server.masterport= port; if (server.master) freeClient(server.master); disconnectAllBlockedClients(); /* Clients blocked in master, now slave. */ disconnectSlaves(); /* Force our slaves to resync with us as well. */ replicationDiscardCachedMaster(); /* Don‘t try a PSYNC. */ freeReplicationBacklog();/* Don‘t allow our chained slaves to PSYNC. */ cancelReplicationHandshake(); server.repl_state = REPL_STATE_CONNECT; server.master_repl_offset = 0; server.repl_down_since = 0; }
Redis 源碼分析 - 復制