mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
DEBUG POPULATE command for fast creation of test databases
This commit is contained in:
parent
a0e7e5f516
commit
59305dc7a9
19
redis.c
19
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 <key>|SWAPIN <key>|SWAPOUT <key>|RELOAD]\r\n"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user