diff options
author | antirez <antirez@gmail.com> | 2011-04-06 12:19:45 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2011-04-06 12:22:09 +0200 |
commit | cf6c3f4b04df7382aba7dd8c229cafcb29e19609 (patch) | |
tree | b4b89022066a64973f9a348164cb436cce8742f8 | |
parent | abdbfc14c04774a979f525c573220e528c096646 (diff) | |
download | redis-cf6c3f4b04df7382aba7dd8c229cafcb29e19609.tar.gz |
OBJECT command implemented
-rw-r--r-- | src/object.c | 39 | ||||
-rw-r--r-- | src/redis.c | 3 | ||||
-rw-r--r-- | src/redis.h | 1 |
3 files changed, 42 insertions, 1 deletions
diff --git a/src/object.c b/src/object.c index de62f504c..2db95be5f 100644 --- a/src/object.c +++ b/src/object.c @@ -439,3 +439,42 @@ unsigned long estimateObjectIdleTime(robj *o) { REDIS_LRU_CLOCK_RESOLUTION; } } + +/* This is an helper function for the DEBUG command. We need to lookup keys + * without any modification of LRU or other parameters. */ +robj *objectCommandLookup(redisClient *c, robj *key) { + dictEntry *de; + + if ((de = dictFind(c->db->dict,key->ptr)) == NULL) return NULL; + return (robj*) dictGetEntryVal(de); +} + +robj *objectCommandLookupOrReply(redisClient *c, robj *key, robj *reply) { + robj *o = objectCommandLookup(c,key); + + if (!o) addReply(c, reply); + return o; +} + +/* Object command allows to inspect the internals of an Redis Object. + * Usage: OBJECT <verb> ... arguments ... */ +void objectCommand(redisClient *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)); + } else { + addReplyError(c,"Syntax error. Try OBJECT (refcount|encoding|idletime)"); + } +} + diff --git a/src/redis.c b/src/redis.c index 90ed02dbf..45be89376 100644 --- a/src/redis.c +++ b/src/redis.c @@ -187,7 +187,8 @@ struct redisCommand readonlyCommandTable[] = { {"punsubscribe",punsubscribeCommand,-1,0,NULL,0,0,0}, {"publish",publishCommand,3,REDIS_CMD_FORCE_REPLICATION,NULL,0,0,0}, {"watch",watchCommand,-2,0,NULL,0,0,0}, - {"unwatch",unwatchCommand,1,0,NULL,0,0,0} + {"unwatch",unwatchCommand,1,0,NULL,0,0,0}, + {"object",objectCommand,-2,0,NULL,0,0,0} }; /*============================ Utility functions ============================ */ diff --git a/src/redis.h b/src/redis.h index fddf29ed0..2b22e6b50 100644 --- a/src/redis.h +++ b/src/redis.h @@ -1008,6 +1008,7 @@ void punsubscribeCommand(redisClient *c); void publishCommand(redisClient *c); void watchCommand(redisClient *c); void unwatchCommand(redisClient *c); +void objectCommand(redisClient *c); #if defined(__GNUC__) void *calloc(size_t count, size_t size) __attribute__ ((deprecated)); |