mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
ROLE command added.
The new ROLE command is designed in order to provide a client with informations about the replication in a fast and easy to use way compared to the INFO command where the same information is also available.
This commit is contained in:
parent
32d0a79f78
commit
d34c2fa3bb
@ -243,6 +243,7 @@ struct redisCommand redisCommandTable[] = {
|
||||
{"pttl",pttlCommand,2,"r",0,NULL,1,1,1,0,0},
|
||||
{"persist",persistCommand,2,"w",0,NULL,1,1,1,0,0},
|
||||
{"slaveof",slaveofCommand,3,"ast",0,NULL,0,0,0,0,0},
|
||||
{"role",roleCommand,1,"ast",0,NULL,0,0,0,0,0},
|
||||
{"debug",debugCommand,-2,"as",0,NULL,0,0,0,0,0},
|
||||
{"config",configCommand,-2,"art",0,NULL,0,0,0,0,0},
|
||||
{"subscribe",subscribeCommand,-2,"rpslt",0,NULL,0,0,0,0,0},
|
||||
|
@ -1394,6 +1394,7 @@ void ttlCommand(redisClient *c);
|
||||
void pttlCommand(redisClient *c);
|
||||
void persistCommand(redisClient *c);
|
||||
void slaveofCommand(redisClient *c);
|
||||
void roleCommand(redisClient *c);
|
||||
void debugCommand(redisClient *c);
|
||||
void msetCommand(redisClient *c);
|
||||
void msetnxCommand(redisClient *c);
|
||||
|
@ -1324,6 +1324,43 @@ void slaveofCommand(redisClient *c) {
|
||||
addReply(c,shared.ok);
|
||||
}
|
||||
|
||||
/* ROLE command: provide information about the role of the instance
|
||||
* (master or slave) and additional information related to replication
|
||||
* in an easy to process format. */
|
||||
void roleCommand(redisClient *c) {
|
||||
if (server.masterhost == NULL) {
|
||||
listIter li;
|
||||
listNode *ln;
|
||||
void *mbcount;
|
||||
int slaves = 0;
|
||||
|
||||
addReplyMultiBulkLen(c,3);
|
||||
addReplyBulkCBuffer(c,"master",6);
|
||||
addReplyLongLong(c,server.master_repl_offset);
|
||||
mbcount = addDeferredMultiBulkLength(c);
|
||||
listRewind(server.slaves,&li);
|
||||
while((ln = listNext(&li))) {
|
||||
redisClient *slave = ln->value;
|
||||
char ip[REDIS_IP_STR_LEN];
|
||||
|
||||
if (anetPeerToString(slave->fd,ip,sizeof(ip),NULL) == -1) continue;
|
||||
if (slave->replstate != REDIS_REPL_ONLINE) continue;
|
||||
addReplyMultiBulkLen(c,3);
|
||||
addReplyBulkCString(c,ip);
|
||||
addReplyBulkLongLong(c,slave->slave_listening_port);
|
||||
addReplyBulkLongLong(c,slave->repl_ack_off);
|
||||
slaves++;
|
||||
}
|
||||
setDeferredMultiBulkLength(c,mbcount,slaves);
|
||||
} else {
|
||||
addReplyMultiBulkLen(c,4);
|
||||
addReplyBulkCBuffer(c,"slave",5);
|
||||
addReplyBulkCString(c,server.masterhost);
|
||||
addReplyLongLong(c,server.masterport);
|
||||
addReplyLongLong(c,server.master->reploff);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send a REPLCONF ACK command to the master to inform it about the current
|
||||
* processed offset. If we are not connected with a master, the command has
|
||||
* no effects. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user