From b28fb3d7530f7d682223e96ed88045f11dfef989 Mon Sep 17 00:00:00 2001 From: Itamar Haber Date: Fri, 24 Nov 2017 19:58:37 +0200 Subject: Prevents `OBJECT freq` with `noeviction` When maxmemory is set to noeviction, idletime is implicitly kept. This renders access frequency nonsensical. --- src/object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/object.c b/src/object.c index d2db7963e..bbf1ca110 100644 --- a/src/object.c +++ b/src/object.c @@ -1035,8 +1035,8 @@ 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); -- cgit v1.2.1 From 02d38f6b514400372089219618ee0b1bc36c7431 Mon Sep 17 00:00:00 2001 From: Itamar Haber Date: Fri, 24 Nov 2017 19:59:05 +0200 Subject: Adds `OBJECT help` --- src/object.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/object.c b/src/object.c index bbf1ca110..4028380d4 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 */ + * Usage: OBJECT */ 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 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); @@ -1041,7 +1055,8 @@ void objectCommand(client *c) { } 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); } } -- cgit v1.2.1