summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2017-11-27 12:41:02 +0100
committerGitHub <noreply@github.com>2017-11-27 12:41:02 +0100
commit29252391c4856e500277bcd84ae0f57b8e6ca661 (patch)
treee535802b35e7448cf942ae21da1457788e704336
parent1c082200224b91c571c7b231b9e4a5e3487dda57 (diff)
parent02d38f6b514400372089219618ee0b1bc36c7431 (diff)
downloadredis-29252391c4856e500277bcd84ae0f57b8e6ca661.tar.gz
Merge pull request #4472 from itamarhaber/object_patch
A minor fix and `help` subcommand for `OBJECT`
-rw-r--r--src/object.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/object.c b/src/object.c
index 0950837c8..e62b5b3d9 100644
--- a/src/object.c
+++ b/src/object.c
@@ -1012,11 +1012,25 @@ robj *objectCommandLookupOrReply(client *c, robj *key, robj *reply) {
}
/* Object command allows to inspect the internals of an Redis Object.
- * Usage: OBJECT <refcount|encoding|idletime> <key> */
+ * Usage: OBJECT <refcount|encoding|idletime|freq> <key> */
void objectCommand(client *c) {
robj *o;
- if (!strcasecmp(c->argv[1]->ptr,"refcount") && c->argc == 3) {
+ if (!strcasecmp(c->argv[1]->ptr,"help") && c->argc == 2) {
+ void *blenp = addDeferredMultiBulkLength(c);
+ int blen = 0;
+ blen++; addReplyStatus(c,
+ "OBJECT <subcommand> key. Subcommands:");
+ blen++; addReplyStatus(c,
+ "refcount -- Return the number of references of the value associated with the specified key.");
+ blen++; addReplyStatus(c,
+ "encoding -- Return the kind of internal representation used in order to store the value associated with a key.");
+ blen++; addReplyStatus(c,
+ "idletime -- Return the number of seconds since the object stored at the specified key is idle.");
+ blen++; addReplyStatus(c,
+ "freq -- Return the inverse logarithmic access frequency counter of the object stored at the specified key.");
+ setDeferredMultiBulkLength(c,blenp,blen);
+ } else if (!strcasecmp(c->argv[1]->ptr,"refcount") && c->argc == 3) {
if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nullbulk))
== NULL) return;
addReplyLongLong(c,o->refcount);
@@ -1035,13 +1049,14 @@ void objectCommand(client *c) {
} else if (!strcasecmp(c->argv[1]->ptr,"freq") && c->argc == 3) {
if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nullbulk))
== NULL) return;
- if (server.maxmemory_policy & MAXMEMORY_FLAG_LRU) {
- addReplyError(c,"An LRU maxmemory policy is selected, access frequency not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust.");
+ if (!(server.maxmemory_policy & MAXMEMORY_FLAG_LFU)) {
+ addReplyError(c,"A non-LFU maxmemory policy is selected, access frequency not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust.");
return;
}
addReplyLongLong(c,o->lru&255);
} else {
- addReplyError(c,"Syntax error. Try OBJECT (refcount|encoding|idletime|freq)");
+ addReplyErrorFormat(c, "Unknown subcommand or wrong number of arguments for '%s'. Try OBJECT help",
+ (char *)c->argv[1]->ptr);
}
}