MCPcopy Create free account
hub / github.com/F-Stack/f-stack / genericHgetallCommand

Function genericHgetallCommand

app/redis-6.2.6/src/t_hash.c:894–930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

892}
893
894void genericHgetallCommand(client *c, int flags) {
895 robj *o;
896 hashTypeIterator *hi;
897 int length, count = 0;
898
899 robj *emptyResp = (flags & OBJ_HASH_KEY && flags & OBJ_HASH_VALUE) ?
900 shared.emptymap[c->resp] : shared.emptyarray;
901 if ((o = lookupKeyReadOrReply(c,c->argv[1],emptyResp))
902 == NULL || checkType(c,o,OBJ_HASH)) return;
903
904 /* We return a map if the user requested keys and values, like in the
905 * HGETALL case. Otherwise to use a flat array makes more sense. */
906 length = hashTypeLength(o);
907 if (flags & OBJ_HASH_KEY && flags & OBJ_HASH_VALUE) {
908 addReplyMapLen(c, length);
909 } else {
910 addReplyArrayLen(c, length);
911 }
912
913 hi = hashTypeInitIterator(o);
914 while (hashTypeNext(hi) != C_ERR) {
915 if (flags & OBJ_HASH_KEY) {
916 addHashIteratorCursorToReply(c, hi, OBJ_HASH_KEY);
917 count++;
918 }
919 if (flags & OBJ_HASH_VALUE) {
920 addHashIteratorCursorToReply(c, hi, OBJ_HASH_VALUE);
921 count++;
922 }
923 }
924
925 hashTypeReleaseIterator(hi);
926
927 /* Make sure we returned the right number of elements. */
928 if (flags & OBJ_HASH_KEY && flags & OBJ_HASH_VALUE) count /= 2;
929 serverAssert(count == length);
930}
931
932void hkeysCommand(client *c) {
933 genericHgetallCommand(c,OBJ_HASH_KEY);

Callers 3

hkeysCommandFunction · 0.85
hvalsCommandFunction · 0.85
hgetallCommandFunction · 0.85

Calls 9

lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
hashTypeLengthFunction · 0.85
addReplyMapLenFunction · 0.85
addReplyArrayLenFunction · 0.85
hashTypeInitIteratorFunction · 0.85
hashTypeNextFunction · 0.85
hashTypeReleaseIteratorFunction · 0.85

Tested by

no test coverage detected