]> git.saurik.com Git - redis.git/commitdiff
DEBUG POPULATE command for fast creation of test databases
authorantirez <antirez@gmail.com>
Fri, 7 May 2010 14:33:47 +0000 (16:33 +0200)
committerantirez <antirez@gmail.com>
Fri, 7 May 2010 14:33:47 +0000 (16:33 +0200)
redis.c

diff --git a/redis.c b/redis.c
index c22a1c8c289e57346257a63ebb31c2912668cadf..c5bdd51e4911bf8aca2feab21ab8c17a2fabfd0c 100644 (file)
--- 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 <key>|SWAPIN <key>|SWAPOUT <key>|RELOAD]\r\n"));