Commit 59305dc7 authored by antirez's avatar antirez
Browse files

DEBUG POPULATE command for fast creation of test databases

parent a0e7e5f5
...@@ -10079,6 +10079,25 @@ static void debugCommand(redisClient *c) { ...@@ -10079,6 +10079,25 @@ static void debugCommand(redisClient *c) {
} else { } else {
addReply(c,shared.err); 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 { } else {
addReplySds(c,sdsnew( addReplySds(c,sdsnew(
"-ERR Syntax error, try DEBUG [SEGFAULT|OBJECT <key>|SWAPIN <key>|SWAPOUT <key>|RELOAD]\r\n")); "-ERR Syntax error, try DEBUG [SEGFAULT|OBJECT <key>|SWAPIN <key>|SWAPOUT <key>|RELOAD]\r\n"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment