Skip to content

Commit bb3c851

Browse files
committed
make zero a valid ttl in HFE
Signed-off-by: cjx-zar <jxchenczar@foxmail.com>
1 parent e4a3e9f commit bb3c851

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/rdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) {
22542254
return NULL;
22552255
}
22562256

2257-
if (rdbtype == RDB_TYPE_HASH_2 && itemexpiry > 0) {
2257+
if (rdbtype == RDB_TYPE_HASH_2 && itemexpiry != EXPIRY_NONE) {
22582258
hashTypeTrackEntry(o, entry);
22592259
}
22602260
}

src/t_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ int hashTypeSet(robj *o, sds field, sds value, long long expiry, int flags) {
372372
* This is needed for HINCRBY* case since in other commands this is handled early by
373373
* hashTypeTryConversion, so this check will be a NOP. */
374374
if (o->encoding == OBJ_ENCODING_LISTPACK) {
375-
if (expiry > 0 || sdslen(field) > server.hash_max_listpack_value || sdslen(value) > server.hash_max_listpack_value)
375+
if (expiry != EXPIRY_NONE || sdslen(field) > server.hash_max_listpack_value || sdslen(value) > server.hash_max_listpack_value)
376376
hashTypeConvert(o, OBJ_ENCODING_HASHTABLE);
377377
}
378378

tests/unit/expire.tcl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,25 @@ start_server {tags {"expire"}} {
965965
fail "key wasn't expired"
966966
}
967967
}
968+
969+
test {Zero is a valid ttl in HFE} {
970+
r flushall
971+
r hset myhash f1 v1
972+
assert_equal [r OBJECT ENCODING myhash] "listpack"
973+
assert_equal [r hsetex myhash exat 0 fields 2 f2 v2 f3 v3] 0
974+
assert_equal [r hlen myhash] 1
975+
assert_equal [r OBJECT ENCODING myhash] "listpack"
976+
r config set import-mode yes
977+
assert_equal [r hsetex myhash exat 0 fields 2 f2 v2 f3 v3] 1
978+
assert_equal [r hlen myhash] 3
979+
assert_equal [r OBJECT ENCODING myhash] "hashtable"
980+
r config set import-mode no
981+
wait_for_condition 30 100 {
982+
[r hlen myhash] == 1
983+
} else {
984+
fail "field wasn't expired"
985+
}
986+
}
968987
}
969988

970989
start_server {tags {expire} overrides {hz 100}} {

0 commit comments

Comments
 (0)