码迷,mamicode.com
首页 > 其他好文 > 详细

Redis 源码分析 - 复制

时间:2017-07-04 16:10:33      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:off   ast   can   free   str   stat   redis   server   car   

 

 

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 源码分析 - 复制

标签:off   ast   can   free   str   stat   redis   server   car   

原文地址:http://www.cnblogs.com/randyma/p/7116868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!