Skip to content

Commit

Permalink
Variadic PING with support for Pub/Sub.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antirez committed Jul 18, 2014
1 parent 23c1408 commit 2264b98
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/redis.c
Expand Up @@ -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},
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2264b98

Please sign in to comment.