From bcd1190644d09b313544aa1b21e46357031ea95e Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 11 Mar 2010 16:10:36 +0100 Subject: [PATCH] Fix for HGET against non Hash type, debug messages used to understand a bit better a corrupted rdb file --- redis.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/redis.c b/redis.c index 48f2e415..73b66177 100644 --- a/redis.c +++ b/redis.c @@ -3451,6 +3451,7 @@ static int rdbLoadDoubleValue(FILE *fp, double *val) { static robj *rdbLoadObject(int type, FILE *fp) { robj *o; + redisLog(REDIS_DEBUG,"LOADING OBJECT %d (at %d)\n",type,ftell(fp)); if (type == REDIS_STRING) { /* Read string value */ if ((o = rdbLoadStringObject(fp)) == NULL) return NULL; @@ -3486,13 +3487,16 @@ static robj *rdbLoadObject(int type, FILE *fp) { o = createZsetObject(); zs = o->ptr; /* Load every single element of the list/set */ + redisLog(REDIS_DEBUG,"SORTED SET LEN: %zu\n", zsetlen); while(zsetlen--) { robj *ele; double *score = zmalloc(sizeof(double)); if ((ele = rdbLoadStringObject(fp)) == NULL) return NULL; + redisLog(REDIS_DEBUG,"ele %s (%d) (%d)\n", (char*)ele->ptr, ftell(fp), zsetlen); tryObjectEncoding(ele); if (rdbLoadDoubleValue(fp,score) == -1) return NULL; + redisLog(REDIS_DEBUG,"score %.17g\n", *score); dictAdd(zs->dict,ele,score); zslInsert(zs->zsl,*score,ele); incrRefCount(ele); /* added to skiplist */ @@ -3540,6 +3544,7 @@ static robj *rdbLoadObject(int type, FILE *fp) { } else { redisAssert(0 != 0); } + redisLog(REDIS_DEBUG,"DONE\n"); return o; } @@ -3594,6 +3599,7 @@ static int rdbLoad(char *filename) { } /* Read key */ if ((keyobj = rdbLoadStringObject(fp)) == NULL) goto eoferr; + redisLog(REDIS_DEBUG,"KEY: %s\n", (char*)keyobj->ptr); /* Read value */ if ((o = rdbLoadObject(type,fp)) == NULL) goto eoferr; /* Add the new object in the hash table */ @@ -5952,6 +5958,11 @@ static void hgetCommand(redisClient *c) { addReply(c,shared.nullbulk); return; } else { + if (o->type != REDIS_HASH) { + addReply(c,shared.wrongtypeerr); + return; + } + if (o->encoding == REDIS_ENCODING_ZIPMAP) { unsigned char *zm = o->ptr; unsigned char *val; -- 2.45.2