From cf6c3f4b04df7382aba7dd8c229cafcb29e19609 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 6 Apr 2011 12:19:45 +0200 Subject: [PATCH 1/5] OBJECT command implemented --- src/object.c | 39 +++++++++++++++++++++++++++++++++++++++ src/redis.c | 3 ++- src/redis.h | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/object.c b/src/object.c index de62f504..2db95be5 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 ... 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 90ed02db..45be8937 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 fddf29ed..2b22e6b5 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)); From 920c45b818ed53ba238e79da06d4ea14aa8bf5a8 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 6 Apr 2011 12:23:01 +0200 Subject: [PATCH 2/5] version is now 2.2.3 --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 0834bc82..611e3006 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define REDIS_VERSION "2.2.2" +#define REDIS_VERSION "2.2.3" From 27fc6199cae1933dc1e700459147d9ee85fa6956 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 6 Apr 2011 12:46:39 +0200 Subject: [PATCH 3/5] CHANGELOG updated --- 00-RELEASENOTES | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/00-RELEASENOTES b/00-RELEASENOTES index 8e04f760..ee8399c7 100644 --- a/00-RELEASENOTES +++ b/00-RELEASENOTES @@ -12,6 +12,16 @@ for 2.0. CHANGELOG --------- +What's new in Redis 2.2.3 +========================= + +* Fixed issue #503. MONITOR + QUIT (and other combinations) could crash + the server. +* OBJECT command implemented. See http://redis.io/commands/object +* Fixed a problem in redis-cli related to escapes in the form "\x..". +* Fixed a minor memory leak in redis-cli +* Saved RDB on SIGTERM on archs where it was not working properly. + What's new in Redis 2.2.2 ========================= From 93db956e061db72749983141cc881329e87e8c1a Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 6 Apr 2011 15:36:10 +0200 Subject: [PATCH 4/5] make sure that OBJECT ENCODING returns skiplist for sorted sets, and not raw, so that once we will merge specially encoded sorted sets everything will make sense. --- src/object.c | 6 +++++- src/redis.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/object.c b/src/object.c index 2db95be5..d8ef59bc 100644 --- a/src/object.c +++ b/src/object.c @@ -93,10 +93,13 @@ robj *createHashObject(void) { robj *createZsetObject(void) { zset *zs = zmalloc(sizeof(*zs)); + robj *o; zs->dict = dictCreate(&zsetDictType,NULL); zs->zsl = zslCreate(); - return createObject(REDIS_ZSET,zs); + o = createObject(REDIS_ZSET,zs); + o->encoding = REDIS_ENCODING_SKIPLIST; + return o; } void freeStringObject(robj *o) { @@ -425,6 +428,7 @@ char *strEncoding(int encoding) { case REDIS_ENCODING_LINKEDLIST: return "linkedlist"; case REDIS_ENCODING_ZIPLIST: return "ziplist"; case REDIS_ENCODING_INTSET: return "intset"; + case REDIS_ENCODING_SKIPLIST: return "skiplist"; default: return "unknown"; } } diff --git a/src/redis.h b/src/redis.h index 2b22e6b5..7c147179 100644 --- a/src/redis.h +++ b/src/redis.h @@ -81,6 +81,7 @@ #define REDIS_ENCODING_LINKEDLIST 4 /* Encoded as regular linked list */ #define REDIS_ENCODING_ZIPLIST 5 /* Encoded as ziplist */ #define REDIS_ENCODING_INTSET 6 /* Encoded as intset */ +#define REDIS_ENCODING_SKIPLIST 7 /* Encoded as skiplist */ /* Object types only used for dumping to disk */ #define REDIS_EXPIRETIME 253 From 2b886275e9756bb8619ad0021048d39b319c5b0a Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 6 Apr 2011 15:39:54 +0200 Subject: [PATCH 5/5] Redis 2.2.4 --- 00-RELEASENOTES | 5 +++++ src/version.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/00-RELEASENOTES b/00-RELEASENOTES index ee8399c7..1bc6c915 100644 --- a/00-RELEASENOTES +++ b/00-RELEASENOTES @@ -12,6 +12,11 @@ for 2.0. CHANGELOG --------- +What's new in Redis 2.2.4 +========================= + +* Return value of OBJECT DEBUG against sorted sets fixed, now is "skiplist". + What's new in Redis 2.2.3 ========================= diff --git a/src/version.h b/src/version.h index 611e3006..6ae276d8 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define REDIS_VERSION "2.2.3" +#define REDIS_VERSION "2.2.4"