Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
569584d4
Unverified
Commit
569584d4
authored
Sep 05, 2024
by
Moti Cohen
Committed by
GitHub
Sep 05, 2024
Browse files
HFE - Simplify logic of HGETALL command (#13425)
parent
ea3e8b79
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/t_hash.c
View file @
569584d4
...
@@ -2428,7 +2428,11 @@ void genericHgetallCommand(client *c, int flags) {
...
@@ -2428,7 +2428,11 @@ void genericHgetallCommand(client *c, int flags) {
/* We return a map if the user requested keys and values, like in the
/* 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. */
* 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
)
{
if
(
flags
&
OBJ_HASH_KEY
&&
flags
&
OBJ_HASH_VALUE
)
{
addReplyMapLen
(
c
,
length
);
addReplyMapLen
(
c
,
length
);
}
else
{
}
else
{
...
@@ -2437,11 +2441,7 @@ void genericHgetallCommand(client *c, int flags) {
...
@@ -2437,11 +2441,7 @@ void genericHgetallCommand(client *c, int flags) {
hi
=
hashTypeInitIterator
(
o
);
hi
=
hashTypeInitIterator
(
o
);
/* Skip expired fields if the hash has an expire time set at global HFE DS. We could
while
(
hashTypeNext
(
hi
,
1
/*skipExpiredFields*/
)
!=
C_ERR
)
{
* 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
)
{
if
(
flags
&
OBJ_HASH_KEY
)
{
if
(
flags
&
OBJ_HASH_KEY
)
{
addHashIteratorCursorToReply
(
c
,
hi
,
OBJ_HASH_KEY
);
addHashIteratorCursorToReply
(
c
,
hi
,
OBJ_HASH_KEY
);
count
++
;
count
++
;
...
...
tests/unit/type/hash-field-expire.tcl
View file @
569584d4
...
@@ -560,10 +560,10 @@ start_server {tags {"external:skip needs:debug"}} {
...
@@ -560,10 +560,10 @@ start_server {tags {"external:skip needs:debug"}} {
# Test with small hash
# Test with small hash
r debug set-active-expire 0
r debug set-active-expire 0
r del myhash
r del myhash
r hset myhash
1
f1 v1 f2 v2 f3 v3 f4 v4 f5 v5 f6 v6
r hset myhash f1 v1 f2 v2 f3 v3 f4 v4 f5 v5 f6 v6
r hpexpire myhash
1
1 NX FIELDS 3 f2 f4 f6
r hpexpire myhash 1 NX FIELDS 3 f2 f4 f6
after 10
after 10
assert_equal
[
lsort
[
r hgetall myhash
1
]]
"f1 f3 f5 v1 v3 v5"
assert_equal
[
lsort
[
r hgetall myhash
]]
"f1 f3 f5 v1 v3 v5"
# Test with large hash
# Test with large hash
r del myhash
r del myhash
...
@@ -573,6 +573,13 @@ start_server {tags {"external:skip needs:debug"}} {
...
@@ -573,6 +573,13 @@ start_server {tags {"external:skip needs:debug"}} {
}
}
after 10
after 10
assert_equal
[
lsort
[
r hgetall myhash
]]
[
lsort
"f1 f2 f3 v1 v2 v3"
]
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
r debug set-active-expire 1
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment