mirror of
https://github.com/redis/redis.git
synced 2026-05-28 04:02:46 -04:00
HFE - Simplify logic of HGETALL command (#13425)
This commit is contained in:
parent
ea3e8b79a1
commit
569584d463
2 changed files with 16 additions and 9 deletions
12
src/t_hash.c
12
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++;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue