Created
July 17, 2010 19:48
-
-
Save jcsalterego/479788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 66cdf0a972d52822e6e0c3e8809c36692ca158e8 Mon Sep 17 00:00:00 2001 | |
| From: Jerry Chen <jerry@apache.org> | |
| Date: Sat, 17 Jul 2010 14:39:18 -0500 | |
| Subject: [PATCH] Added 'version' command, tied to REDIS_VERSION | |
| --- | |
| src/redis-cli.c | 3 ++- | |
| src/redis.c | 11 ++++++++++- | |
| src/redis.h | 1 + | |
| 3 files changed, 13 insertions(+), 2 deletions(-) | |
| diff --git a/src/redis-cli.c b/src/redis-cli.c | |
| index dac8286..8342fcf 100644 | |
| --- a/src/redis-cli.c | |
| +++ b/src/redis-cli.c | |
| @@ -240,7 +240,8 @@ static int cliSendCommand(int argc, char **argv, int repeat) { | |
| int fd, j, retval = 0; | |
| sds cmd; | |
| - config.raw_output = !strcasecmp(command,"info"); | |
| + config.raw_output = !strcasecmp(command,"info") | |
| + || !strcasecmp(command,"version"); | |
| if (!strcasecmp(command,"shutdown")) config.shutdown = 1; | |
| if (!strcasecmp(command,"monitor")) config.monitor_mode = 1; | |
| if (!strcasecmp(command,"subscribe") || | |
| diff --git a/src/redis.c b/src/redis.c | |
| index 86536b4..d285814 100644 | |
| --- a/src/redis.c | |
| +++ b/src/redis.c | |
| @@ -178,7 +178,8 @@ struct redisCommand readonlyCommandTable[] = { | |
| {"punsubscribe",punsubscribeCommand,-1,REDIS_CMD_INLINE,NULL,0,0,0}, | |
| {"publish",publishCommand,3,REDIS_CMD_BULK|REDIS_CMD_FORCE_REPLICATION,NULL,0,0,0}, | |
| {"watch",watchCommand,-2,REDIS_CMD_INLINE,NULL,0,0,0}, | |
| - {"unwatch",unwatchCommand,1,REDIS_CMD_INLINE,NULL,0,0,0} | |
| + {"unwatch",unwatchCommand,1,REDIS_CMD_INLINE,NULL,0,0,0}, | |
| + {"version",versionCommand,1,REDIS_CMD_INLINE,NULL,0,0,0} | |
| }; | |
| /*============================ Utility functions ============================ */ | |
| @@ -1250,6 +1251,14 @@ void infoCommand(redisClient *c) { | |
| addReply(c,shared.crlf); | |
| } | |
| +void versionCommand(redisClient *c) { | |
| + sds info = sdscatprintf(sdsempty(), "%s\r\n", REDIS_VERSION); | |
| + addReplySds(c,sdscatprintf(sdsempty(),"$%lu\r\n", | |
| + (unsigned long)sdslen(info))); | |
| + addReplySds(c,info); | |
| + addReply(c,shared.crlf); | |
| +} | |
| + | |
| void monitorCommand(redisClient *c) { | |
| /* ignore MONITOR if aleady slave or in monitor mode */ | |
| if (c->flags & REDIS_SLAVE) return; | |
| diff --git a/src/redis.h b/src/redis.h | |
| index 4ff8362..5295e21 100644 | |
| --- a/src/redis.h | |
| +++ b/src/redis.h | |
| @@ -883,5 +883,6 @@ void punsubscribeCommand(redisClient *c); | |
| void publishCommand(redisClient *c); | |
| void watchCommand(redisClient *c); | |
| void unwatchCommand(redisClient *c); | |
| +void versionCommand(redisClient *c); | |
| #endif | |
| -- | |
| 1.7.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment