| 892 | } |
| 893 | |
| 894 | void 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 | |
| 932 | void hkeysCommand(client *c) { |
| 933 | genericHgetallCommand(c,OBJ_HASH_KEY); |
no test coverage detected