From d4222e6bee4b6f58faec93cfb8179b695d5cdb9e Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 25 Sep 2014 17:01:56 +0200 Subject: [PATCH] DEBUG POPULATE two args form implemented. The old DEBUG POPULATE form for automatic creation of test keys is: DEBUG POPULATE Now an additional form is available: DEBUG POPULATE When prefix is not specified, it defaults to "key", so the keys are named incrementally from key:0 to key:. Otherwise the specified prefix is used instead of "key". The command is useful in order to populate different Redis instances with key names guaranteed to don't collide. There are other debugging uses, for example it is possible to add additional N keys using a count of N and a random prefix at every call. --- src/debug.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/debug.c b/src/debug.c index 50c9d9b2..641b1002 100644 --- a/src/debug.c +++ b/src/debug.c @@ -325,7 +325,8 @@ void debugCommand(redisClient *c) { (long long) sdslen(val->ptr), (long long) sdsavail(val->ptr)); } - } else if (!strcasecmp(c->argv[1]->ptr,"populate") && c->argc == 3) { + } else if (!strcasecmp(c->argv[1]->ptr,"populate") && + (c->argc == 3 || c->argc == 4)) { long keys, j; robj *key, *val; char buf[128]; @@ -334,7 +335,8 @@ void debugCommand(redisClient *c) { return; dictExpand(c->db->dict,keys); for (j = 0; j < keys; j++) { - snprintf(buf,sizeof(buf),"key:%lu",j); + snprintf(buf,sizeof(buf),"%s:%lu", + (c->argc == 3) ? "key" : c->argv[3]->ptr, j); key = createStringObject(buf,strlen(buf)); if (lookupKeyRead(c->db,key) != NULL) { decrRefCount(key);