Skip to content

Commit

Permalink
Store SELECTed database for reconnect (issue #468)
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Mar 6, 2011
1 parent 45332cc commit 699465c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/redis-cli.c
Expand Up @@ -264,11 +264,9 @@ static int cliAuth() {
/* Send SELECT dbnum to the server */
static int cliSelect() {
redisReply *reply;
char dbnum[16];
if (config.dbnum == 0) return REDIS_OK;

snprintf(dbnum,sizeof(dbnum),"%d",config.dbnum);
reply = redisCommand(context,"SELECT %s",dbnum);
reply = redisCommand(context,"SELECT %d",config.dbnum);
if (reply != NULL) {
freeReplyObject(reply);
return REDIS_OK;
Expand Down Expand Up @@ -492,6 +490,10 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
if (cliReadReply(output_raw) != REDIS_OK) {
free(argvlen);
return REDIS_ERR;
} else {
/* Store database number when SELECT was successfully executed. */
if (!strcasecmp(command,"select") && argc == 2)
config.dbnum = atoi(argv[1]);
}
}

Expand Down

0 comments on commit 699465c

Please sign in to comment.