예제 #1
0
파일: vr_object.c 프로젝트: vipshop/vire
/* Object command allows to inspect the internals of an Redis Object.
 * Usage: OBJECT <refcount|encoding|idletime> <key> */
void objectCommand(client *c) {
    robj *o;

    if (!strcasecmp(c->argv[1]->ptr,"encoding") && c->argc == 3) {
        fetchInternalDbByKey(c,c->argv[2]);
        lockDbRead(c->db);
        if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nullbulk))
                == NULL) {
            unlockDb(c->db);
            return;
        }
        addReplyBulkCString(c,strEncoding(o->encoding));
        unlockDb(c->db);
    } else if (!strcasecmp(c->argv[1]->ptr,"idletime") && c->argc == 3) {
        fetchInternalDbByKey(c,c->argv[2]);
        lockDbRead(c->db);
        if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nullbulk))
                == NULL) {
            unlockDb(c->db);
            return;
        }
        addReplyLongLong(c,estimateObjectIdleTime(o)/1000);
        unlockDb(c->db);
    } else {
        addReplyError(c,"Syntax error. Try OBJECT (encoding|idletime)");
    }
}
예제 #2
0
/* Object command allows to inspect the internals of an Redis Object.
 * Usage: OBJECT <refcount|encoding|idletime> <key> */
void objectCommand(client *c) {
    robj *o;

    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);
    } else if (!strcasecmp(c->argv[1]->ptr,"encoding") && c->argc == 3) {
        if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nullbulk))
                == NULL) return;
        addReplyBulkCString(c,strEncoding(o->encoding));
    } else if (!strcasecmp(c->argv[1]->ptr,"idletime") && c->argc == 3) {
        if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nullbulk))
                == NULL) return;
        addReplyLongLong(c,estimateObjectIdleTime(o)/1000);
    } else {
        addReplyError(c,"Syntax error. Try OBJECT (refcount|encoding|idletime)");
    }
}