Redis 源码分析 - 复制

 

 

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;
}

 

posted @ 2017-07-04 15:28  大尾巴狼R  阅读(240)  评论(0)    收藏  举报