Unverified Commit 569584d4 authored by Moti Cohen's avatar Moti Cohen Committed by GitHub
Browse files

HFE - Simplify logic of HGETALL command (#13425)

parent ea3e8b79
......@@ -2428,7 +2428,11 @@ void genericHgetallCommand(client *c, int flags) {
/* We return a map if the user requested keys and values, like in the
* HGETALL case. Otherwise to use a flat array makes more sense. */
length = hashTypeLength(o, 1 /*subtractExpiredFields*/);
if ((length = hashTypeLength(o, 1 /*subtractExpiredFields*/)) == 0) {
addReply(c, emptyResp);
return;
}
if (flags & OBJ_HASH_KEY && flags & OBJ_HASH_VALUE) {
addReplyMapLen(c, length);
} else {
......@@ -2437,11 +2441,7 @@ void genericHgetallCommand(client *c, int flags) {
hi = hashTypeInitIterator(o);
/* Skip expired fields if the hash has an expire time set at global HFE DS. We could
* set it to constant 1, but then it will make another lookup for each field expiration */
int skipExpiredFields = (EB_EXPIRE_TIME_INVALID == hashTypeGetMinExpire(o, 0)) ? 0 : 1;
while (hashTypeNext(hi, skipExpiredFields) != C_ERR) {
while (hashTypeNext(hi, 1 /*skipExpiredFields*/) != C_ERR) {
if (flags & OBJ_HASH_KEY) {
addHashIteratorCursorToReply(c, hi, OBJ_HASH_KEY);
count++;
......
......@@ -560,10 +560,10 @@ start_server {tags {"external:skip needs:debug"}} {
# Test with small hash
r debug set-active-expire 0
r del myhash
r hset myhash1 f1 v1 f2 v2 f3 v3 f4 v4 f5 v5 f6 v6
r hpexpire myhash1 1 NX FIELDS 3 f2 f4 f6
r hset myhash f1 v1 f2 v2 f3 v3 f4 v4 f5 v5 f6 v6
r hpexpire myhash 1 NX FIELDS 3 f2 f4 f6
after 10
assert_equal [lsort [r hgetall myhash1]] "f1 f3 f5 v1 v3 v5"
assert_equal [lsort [r hgetall myhash]] "f1 f3 f5 v1 v3 v5"
# Test with large hash
r del myhash
......@@ -573,6 +573,13 @@ start_server {tags {"external:skip needs:debug"}} {
}
after 10
assert_equal [lsort [r hgetall myhash]] [lsort "f1 f2 f3 v1 v2 v3"]
# hash that all fields are expired return empty result
r del myhash
r hset myhash f1 v1 f2 v2 f3 v3 f4 v4 f5 v5 f6 v6
r hpexpire myhash 1 FIELDS 6 f1 f2 f3 f4 f5 f6
after 10
assert_equal [r hgetall myhash] ""
r debug set-active-expire 1
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment