From 269e80526f1f90142661b9e25bff3a08639ce59c Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 8 Jun 2018 11:17:20 +0200 Subject: [PATCH] Implement DEBUG htstats-key. --- src/debug.c | 29 +++++++++++++++++++++++++++++ src/redis-cli.c | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/debug.c b/src/debug.c index 0ab864e7f..078ac3c67 100644 --- a/src/debug.c +++ b/src/debug.c @@ -290,6 +290,7 @@ void debugCommand(client *c) { "crash-and-recover -- Hard crash and restart after delay.", "digest -- Outputs an hex signature representing the current DB content.", "htstats -- Return hash table statistics of the specified Redis database.", +"htstats-key -- Like htstats but for the hash table stored as key's value.", "loadaof -- Flush the AOF buffers on disk and reload the AOF in memory.", "lua-always-replicate-commands (0|1) -- Setting it to 1 makes Lua replication defaulting to replicating single commands, without the script having to enable effects replication.", "object -- Show low level info about key and associated value.", @@ -547,6 +548,34 @@ NULL stats = sdscat(stats,buf); addReplyBulkSds(c,stats); + } else if (!strcasecmp(c->argv[1]->ptr,"htstats-key") && c->argc == 3) { + robj *o; + dict *ht = NULL; + + if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nokeyerr)) + == NULL) return; + + /* Get the hash table reference from the object, if possible. */ + switch (o->encoding) { + case OBJ_ENCODING_SKIPLIST: + { + zset *zs = o->ptr; + ht = zs->dict; + } + break; + case OBJ_ENCODING_HT: + ht = o->ptr; + break; + } + + if (ht == NULL) { + addReplyError(c,"The value stored at the specified key is not " + "represented using an hash table"); + } else { + char buf[4096]; + dictGetStats(buf,sizeof(buf),ht); + addReplyBulkCString(c,buf); + } } else if (!strcasecmp(c->argv[1]->ptr,"change-repl-id") && c->argc == 2) { serverLog(LL_WARNING,"Changing replication IDs after receiving DEBUG change-repl-id"); changeReplicationId(); diff --git a/src/redis-cli.c b/src/redis-cli.c index 0ee9f84ed..af5e6a230 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1075,6 +1075,8 @@ static int cliSendCommand(int argc, char **argv, long repeat) { if (!strcasecmp(command,"info") || (argc >= 2 && !strcasecmp(command,"debug") && !strcasecmp(argv[1],"htstats")) || + (argc >= 2 && !strcasecmp(command,"debug") && + !strcasecmp(argv[1],"htstats-key")) || (argc >= 2 && !strcasecmp(command,"memory") && (!strcasecmp(argv[1],"malloc-stats") || !strcasecmp(argv[1],"doctor"))) ||