Repository: valkey-io/valkey
File: src/t_hash.c (C)

Code before:
            addWritePreparedReplyMapLen(wpc, length);
        } else {
            addWritePreparedReplyArrayLen(wpc, length);
        }
    } else {
        replylen = addReplyDeferredLen(c);
    }

    hashTypeInitIterator(o, &hi);
    while (hashTypeNext(&hi) != C_ERR) {
        if (flags & OBJ_HASH_FIELD) {
            addHashIteratorCursorToReply(wpc, &hi, OBJ_HASH_FIELD);
            count++;
        }
        if (flags & OBJ_HASH_VALUE) {
            addHashIteratorCursorToReply(wpc, &hi, OBJ_HASH_VALUE);
            count++;
        }
    }

    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);
            count /= 2;
        } else {
            setDeferredArrayLen(c, replylen, count);
        }
    }
}

void hkeysCommand(client *c) {
    genericHgetallCommand(c, OBJ_HASH_FIELD);
}

void hvalsCommand(client *c) {
    genericHgetallCommand(c, OBJ_HASH_VALUE);
}

void hgetallCommand(client *c) {
    genericHgetallCommand(c, OBJ_HASH_FIELD | OBJ_HASH_VALUE);
}

void hexistsCommand(client *c) {
    robj *o;
    if ((o = lookupKeyReadOrReply(c, c->argv[1], shared.czero)) == NULL || checkType(c, o, OBJ_HASH)) return;
    addReply(c, hashTypeExists(o, c->argv[2]->ptr) ? shared.cone : shared.czero);
}

void hscanCommand(client *c) {

Review comment (suggestion):
This looks like an old typo that was preserved in this change.

Dividing count by two twice doens't make sense. `count` is a local variable and this is the last use, so I believe a simple `count / 2` is correct and more clear.

```suggestion
            setDeferredMapLen(c, replylen, count / 2);
```

Code after:
            addWritePreparedReplyMapLen(wpc, length);
        } else {
            addWritePreparedReplyArrayLen(wpc, length);
        }
    } else {
        replylen = addReplyDeferredLen(c);
    }

    hashTypeInitIterator(o, &hi);
    while (hashTypeNext(&hi) != C_ERR) {
        if (flags & OBJ_HASH_FIELD) {
            addHashIteratorCursorToReply(wpc, &hi, OBJ_HASH_FIELD);
            count++;
        }
        if (flags & OBJ_HASH_VALUE) {
            addHashIteratorCursorToReply(wpc, &hi, OBJ_HASH_VALUE);
            count++;
        }
    }

    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);
        }
    }
}

void hkeysCommand(client *c) {
    genericHgetallCommand(c, OBJ_HASH_FIELD);
}

void hvalsCommand(client *c) {
    genericHgetallCommand(c, OBJ_HASH_VALUE);
}

void hgetallCommand(client *c) {
    genericHgetallCommand(c, OBJ_HASH_FIELD | OBJ_HASH_VALUE);
}

void hexistsCommand(client *c) {
    robj *o;
    if ((o = lookupKeyReadOrReply(c, c->argv[1], shared.czero)) == NULL || checkType(c, o, OBJ_HASH)) return;
    addReply(c, hashTypeExists(o, c->argv[2]->ptr) ? shared.cone : shared.czero);
}

void hscanCommand(client *c) {
    robj *o;