Variadic PING with support for Pub/Sub.

PING can now be called with an additional arugment, behaving exactly
like the ECHO command. PING can now also be called in Pub/Sub mode (with
one more more subscriptions to channels / patterns) in order to trigger
the delivery of an asynchronous pong message with the optional payload.

This fixes issue #420.
This commit is contained in:
antirez 2014-07-16 17:47:17 +02:00
parent 59cf0824d9
commit 27839e5ecb

View File

@ -224,7 +224,7 @@ struct redisCommand redisCommandTable[] = {
{"scan",scanCommand,-2,"rR",0,NULL,0,0,0,0,0},
{"dbsize",dbsizeCommand,1,"rF",0,NULL,0,0,0,0,0},
{"auth",authCommand,2,"rsltF",0,NULL,0,0,0,0,0},
{"ping",pingCommand,1,"rtF",0,NULL,0,0,0,0,0},
{"ping",pingCommand,-1,"rtF",0,NULL,0,0,0,0,0},
{"echo",echoCommand,2,"rF",0,NULL,0,0,0,0,0},
{"save",saveCommand,1,"ars",0,NULL,0,0,0,0,0},
{"bgsave",bgsaveCommand,1,"ar",0,NULL,0,0,0,0,0},
@ -2398,8 +2398,28 @@ void authCommand(redisClient *c) {
}
}
/* The PING command. It works in a different way if the client is in
* in Pub/Sub mode. */
void pingCommand(redisClient *c) {
addReply(c,shared.pong);
/* The command takes zero or one arguments. */
if (c->argc > 2) {
addReply(c,shared.syntaxerr);
return;
}
if (c->flags & REDIS_PUBSUB) {
addReply(c,shared.mbulkhdr[2]);
addReplyBulkCBuffer(c,"pong",4);
if (c->argc == 1)
addReplyBulkCBuffer(c,"",0);
else
addReplyBulk(c,c->argv[1]);
} else {
if (c->argc == 1)
addReply(c,shared.pong);
else
addReplyBulk(c,c->argv[1]);
}
}
void echoCommand(redisClient *c) {