From c3cb078d4684d3daba7cf2824fe41c747f69ef51 Mon Sep 17 00:00:00 2001 From: antirez Date: Sun, 14 Jun 2009 23:34:25 +0200 Subject: [PATCH] number of keys info in INFO command thanks to Diego Rosario Brogna --- TODO | 2 -- redis.c | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 37dbeed4..fcf73b3c 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ BEFORE REDIS 1.0.0-rc1 - * SPOP man page * Add number of keys for every DB in INFO - * check 'server.dirty' everywere. Make it proprotional to the number of objects modified. * Cover most of the source code with test-redis.tcl * Remove tmp-.... files when saving child exits in the wrong way, to do so use tmp-pid.rdb as filename so that the parent can rebuild the file name just from the child pid. diff --git a/redis.c b/redis.c index 889a9e73..b05d92ff 100644 --- a/redis.c +++ b/redis.c @@ -734,8 +734,8 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD size = dictSlots(server.db[j].dict); used = dictSize(server.db[j].dict); vkeys = dictSize(server.db[j].expires); - if (!(loops % 5) && used > 0) { - redisLog(REDIS_DEBUG,"DB %d: %d keys (%d volatile) in %d slots HT.",j,used,vkeys,size); + if (!(loops % 5) && (used || vkeys)) { + redisLog(REDIS_DEBUG,"DB %d: %lld keys (%lld volatile) in %lld slots HT.",j,used,vkeys,size); /* dictPrintStats(server.dict); */ } } @@ -3602,6 +3602,7 @@ static void sortCommand(redisClient *c) { static void infoCommand(redisClient *c) { sds info; time_t uptime = time(NULL)-server.stat_starttime; + int j; info = sdscatprintf(sdsempty(), "redis_version:%s\r\n" @@ -3642,6 +3643,16 @@ static void infoCommand(redisClient *c) { (int)(time(NULL)-server.master->lastinteraction) ); } + for (j = 0; j < server.dbnum; j++) { + long long keys, vkeys; + + keys = dictSize(server.db[j].dict); + vkeys = dictSize(server.db[j].expires); + if (keys || vkeys) { + info = sdscatprintf(info, "db%d: keys=%lld,expires=%lld\r\n", + j, keys, vkeys); + } + } addReplySds(c,sdscatprintf(sdsempty(),"$%d\r\n",sdslen(info))); addReplySds(c,info); addReply(c,shared.crlf);