From 59305dc7a91a0572c5cc0d5f7e3d0e624311542a Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 7 May 2010 16:33:47 +0200 Subject: [PATCH] DEBUG POPULATE command for fast creation of test databases --- redis.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/redis.c b/redis.c index c22a1c8c..c5bdd51e 100644 --- a/redis.c +++ b/redis.c @@ -10079,6 +10079,25 @@ static void debugCommand(redisClient *c) { } else { addReply(c,shared.err); } + } else if (!strcasecmp(c->argv[1]->ptr,"populate") && c->argc == 3) { + long keys, j; + robj *key, *val; + char buf[128]; + + if (getLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != REDIS_OK) + return; + for (j = 0; j < keys; j++) { + snprintf(buf,sizeof(buf),"key:%lu",j); + key = createStringObject(buf,strlen(buf)); + if (lookupKeyRead(c->db,key) != NULL) { + decrRefCount(key); + continue; + } + snprintf(buf,sizeof(buf),"value:%lu",j); + val = createStringObject(buf,strlen(buf)); + dictAdd(c->db->dict,key,val); + } + addReply(c,shared.ok); } else { addReplySds(c,sdsnew( "-ERR Syntax error, try DEBUG [SEGFAULT|OBJECT |SWAPIN |SWAPOUT |RELOAD]\r\n"));