From 321b0e13f6d48e61ee558c2ba32e86430bbe55af Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 23 May 2009 10:56:32 +0200 Subject: [PATCH] SLAVEOF command implemented for replication remote control --- Changelog | 6 ++++++ TODO | 2 ++ redis-cli.c | 1 + redis.c | 26 +++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index bc4a8b64..2298f008 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,9 @@ +2009-05-22 Fix: no connection timeout for the master! +2009-05-22 replication slave timeout when receiving the initial bulk data set to 3600 seconds, now that replication is non-blocking the server must save the db before to start the async replication and this can take a lot of time with huge datasets +2009-05-22 README tutorial now reflects the new proto +2009-05-22 critical bug about glueoutputbuffers=yes fixed. Under load and with pipelining and clients disconnecting on the middle of the chat with the server, Redis could block. Now it's ok +2009-05-22 TTL command doc added +2009-05-22 TTL command implemented 2009-05-22 S*STORE now return the cardinality of the resulting set 2009-05-22 rubyredis more compatible with Redis-rb 2009-05-21 minor indentation fix diff --git a/TODO b/TODO index f09830e2..483d6fcb 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ BEFORE REDIS 1.0.0-rc1 + * redis-cli should work on scripts too + * Replication status in INFO command. role: (master|slave) slaveof: , slavestatus: (disconnected|ok) * Warning if using default config, with hint about 'redis-server redis.conf' * Add number of keys for every DB in INFO * maxmemory support diff --git a/redis-cli.c b/redis-cli.c index 85652d2c..d008d6e2 100644 --- a/redis-cli.c +++ b/redis-cli.c @@ -110,6 +110,7 @@ static struct redisCommand cmdTable[] = { {"mget",-2,REDIS_CMD_INLINE}, {"expire",3,REDIS_CMD_INLINE}, {"ttl",2,REDIS_CMD_INLINE}, + {"slaveof",3,REDIS_CMD_INLINE}, {NULL,0,0} }; diff --git a/redis.c b/redis.c index 358463cd..a7c3f211 100644 --- a/redis.c +++ b/redis.c @@ -362,6 +362,7 @@ static void monitorCommand(redisClient *c); static void expireCommand(redisClient *c); static void getSetCommand(redisClient *c); static void ttlCommand(redisClient *c); +static void slaveofCommand(redisClient *c); /*================================= Globals ================================= */ @@ -406,6 +407,7 @@ static struct redisCommand cmdTable[] = { {"move",moveCommand,3,REDIS_CMD_INLINE}, {"rename",renameCommand,3,REDIS_CMD_INLINE}, {"renamenx",renamenxCommand,3,REDIS_CMD_INLINE}, + {"expire",expireCommand,3,REDIS_CMD_INLINE}, {"keys",keysCommand,2,REDIS_CMD_INLINE}, {"dbsize",dbsizeCommand,1,REDIS_CMD_INLINE}, {"auth",authCommand,2,REDIS_CMD_INLINE}, @@ -422,8 +424,8 @@ static struct redisCommand cmdTable[] = { {"sort",sortCommand,-2,REDIS_CMD_INLINE}, {"info",infoCommand,1,REDIS_CMD_INLINE}, {"monitor",monitorCommand,1,REDIS_CMD_INLINE}, - {"expire",expireCommand,3,REDIS_CMD_INLINE}, {"ttl",ttlCommand,2,REDIS_CMD_INLINE}, + {"slaveof",slaveofCommand,3,REDIS_CMD_INLINE}, {NULL,NULL,0,0} }; @@ -3918,6 +3920,28 @@ static int syncWithMaster(void) { return REDIS_OK; } +static void slaveofCommand(redisClient *c) { + if (!strcasecmp(c->argv[1]->ptr,"no") && + !strcasecmp(c->argv[2]->ptr,"one")) { + if (server.masterhost) { + sdsfree(server.masterhost); + server.masterhost = NULL; + if (server.master) freeClient(server.master); + server.replstate = REDIS_REPL_NONE; + redisLog(REDIS_NOTICE,"MASTER MODE enabled (user request)"); + } + } else { + sdsfree(server.masterhost); + server.masterhost = sdsdup(c->argv[1]->ptr); + server.masterport = atoi(c->argv[2]->ptr); + if (server.master) freeClient(server.master); + server.replstate = REDIS_REPL_CONNECT; + redisLog(REDIS_NOTICE,"SLAVE OF %s:%d enabled (user request)", + server.masterhost, server.masterport); + } + addReply(c,shared.ok); +} + /* =================================== Main! ================================ */ #ifdef __linux__ -- 2.45.2