summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-06-08 11:17:20 +0200
committerantirez <antirez@gmail.com>2018-06-08 11:17:20 +0200
commit269e80526f1f90142661b9e25bff3a08639ce59c (patch)
treeed540a7f8b45669e246e5e11ddad3a7235aa98ea
parent97e1f6812cb183bf989ac3bce35e7f59d220df36 (diff)
downloadredis-269e80526f1f90142661b9e25bff3a08639ce59c.tar.gz
Implement DEBUG htstats-key.
-rw-r--r--src/debug.c29
-rw-r--r--src/redis-cli.c2
2 files changed, 31 insertions, 0 deletions
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 <milliseconds> -- Hard crash and restart after <milliseconds> delay.",
"digest -- Outputs an hex signature representing the current DB content.",
"htstats <dbid> -- Return hash table statistics of the specified Redis database.",
+"htstats-key <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 <key> -- 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"))) ||