diff --git a/src/t_hash.c b/src/t_hash.c index 66a3083c6..f06040e33 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -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++; diff --git a/tests/unit/type/hash-field-expire.tcl b/tests/unit/type/hash-field-expire.tcl index 2c0ff8abd..d955384a9 100644 --- a/tests/unit/type/hash-field-expire.tcl +++ b/tests/unit/type/hash-field-expire.tcl @@ -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 }