Skip to content

Instantly share code, notes, and snippets.

@dvv
Created June 1, 2010 14:41
Show Gist options
  • Select an option

  • Save dvv/421009 to your computer and use it in GitHub Desktop.

Select an option

Save dvv/421009 to your computer and use it in GitHub Desktop.
static void genericHgetallCommand(redisClient *c, int flags) {
robj *o, *lenobj, *obj;
unsigned long count = 0;
hashIterator *hi;
lenobj = createObject(REDIS_STRING,NULL);
addReply(c,lenobj);
decrRefCount(lenobj);
for (int i = 1; i < c->argc; ++i) {
if ((o = lookupKeyReadOrReply(c,c->argv[i],shared.emptymultibulk)) == NULL
|| checkType(c,o,REDIS_HASH)) break;
hi = hashInitIterator(o);
while (hashNext(hi) != REDIS_ERR) {
if (flags & REDIS_HASH_KEY) {
obj = hashCurrent(hi,REDIS_HASH_KEY);
addReplyBulk(c,obj);
decrRefCount(obj);
count++;
}
if (flags & REDIS_HASH_VALUE) {
obj = hashCurrent(hi,REDIS_HASH_VALUE);
addReplyBulk(c,obj);
decrRefCount(obj);
count++;
}
}
hashReleaseIterator(hi);
}
lenobj->ptr = sdscatprintf(sdsempty(),"*%lu\r\n",count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment