Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions src/t_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,27 +1613,14 @@ void genericHgetallCommand(client *c, int flags) {
hashTypeIterator hi;
int count = 0;

void *replylen = NULL; /* In case we use a deferred reply path */

robj *emptyResp = (flags & OBJ_HASH_FIELD && flags & OBJ_HASH_VALUE) ? shared.emptymap[c->resp] : shared.emptyarray;
if ((o = lookupKeyReadOrReply(c, c->argv[1], emptyResp)) == NULL || checkType(c, o, OBJ_HASH)) return;

writePreparedClient *wpc = prepareClientForFutureWrites(c);
if (!wpc) return;
/* We return a map if the user requested fields and values, like in the
* HGETALL case. Otherwise to use a flat array makes more sense. */

if (!hashTypeHasVolatileFields(o)) {
unsigned long length = hashTypeLength(o);
if (flags & OBJ_HASH_FIELD && flags & OBJ_HASH_VALUE) {
addWritePreparedReplyMapLen(wpc, length);
} else {
addWritePreparedReplyArrayLen(wpc, length);
}
} else {
replylen = addReplyDeferredLen(c);
}

void *replylen = addReplyDeferredLen(c);
hashTypeInitIterator(o, &hi);
while (hashTypeNext(&hi) != C_ERR) {
if (flags & OBJ_HASH_FIELD) {
Expand All @@ -1647,13 +1634,12 @@ void genericHgetallCommand(client *c, int flags) {
}

hashTypeResetIterator(&hi);
/* In case of deferred reply, make sure we returned the right number of elements. */
if (replylen) {
if (flags & OBJ_HASH_FIELD && flags & OBJ_HASH_VALUE) {
setDeferredMapLen(c, replylen, count /= 2);
} else {
setDeferredArrayLen(c, replylen, count);
}
/* Make sure we returned the right number of elements. */
if (flags & OBJ_HASH_FIELD && flags & OBJ_HASH_VALUE) {
setDeferredMapLen(c, replylen, count /= 2);
count /= 2;
} else {
setDeferredArrayLen(c, replylen, count);
}
}

Expand Down
Loading