diff options
author | antirez <antirez@gmail.com> | 2014-09-25 17:01:56 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-10-29 14:36:55 +0100 |
commit | a37f8ec8b478fccc2266703aef6bc5f334582b18 (patch) | |
tree | fcc137f028dfc237171f8a635a986573193e8523 | |
parent | b2509d7759b18e08445f4bc479a369f7b018379c (diff) | |
download | redis-a37f8ec8b478fccc2266703aef6bc5f334582b18.tar.gz |
DEBUG POPULATE two args form implemented.
The old DEBUG POPULATE form for automatic creation of test keys is:
DEBUG POPULATE <count>
Now an additional form is available:
DEBUG POPULATE <count> <prefix>
When prefix is not specified, it defaults to "key", so the keys are
named incrementally from key:0 to key:<count-1>. 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.
-rw-r--r-- | src/debug.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/debug.c b/src/debug.c index 99f8b89ca..a6c2bfbbf 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); |