Skip to content

Commit 6465314

Browse files
committed
handle negative ttl correctly
Signed-off-by: Ran Shidlansik <[email protected]>
1 parent f62c163 commit 6465314

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/t_hash.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,18 +1569,20 @@ void hsetexCommand(client *c) {
15691569
set_flags |= HASH_SET_KEEP_EXPIRY;
15701570
else if (expire) {
15711571
if (getLongLongFromObjectOrReply(c, expire, &when, NULL) != C_OK) return;
1572+
long long basetime = (flags & (OBJ_EXAT | OBJ_PXAT)) ? 0 : commandTimeSnapshot();
1573+
15721574
if (unit == UNIT_SECONDS) {
15731575
if (when > LLONG_MAX / 1000 || when < LLONG_MIN / 1000) {
15741576
addReplyErrorExpireTime(c);
15751577
return;
15761578
}
15771579
when *= 1000;
15781580
}
1579-
if ((flags & (OBJ_EXAT | OBJ_PXAT)) && when > LLONG_MAX - commandTimeSnapshot()) {
1581+
if (when > LLONG_MAX - basetime) {
15801582
addReplyErrorExpireTime(c);
15811583
return;
15821584
}
1583-
when += commandTimeSnapshot();
1585+
when += basetime;
15841586

15851587
if (((flags & OBJ_PXAT) || (flags & OBJ_EXAT)) && checkAlreadyExpired(when)) {
15861588
set_expired = 1;
@@ -1678,20 +1680,24 @@ void hgetexCommand(client *c) {
16781680
persist = 1;
16791681
} else if (expire) {
16801682
if (getLongLongFromObjectOrReply(c, expire, &when, NULL) != C_OK) return;
1683+
long long basetime = (flags & (OBJ_EXAT | OBJ_PXAT)) ? 0 : commandTimeSnapshot();
1684+
16811685
if (unit == UNIT_SECONDS) {
16821686
if (when > LLONG_MAX / 1000 || when < LLONG_MIN / 1000) {
16831687
addReplyErrorExpireTime(c);
16841688
return;
16851689
}
16861690
when *= 1000;
16871691
}
1688-
if ((flags & (OBJ_EXAT | OBJ_PXAT)) && when > LLONG_MAX - commandTimeSnapshot()) {
1692+
if (when > LLONG_MAX - basetime) {
16891693
addReplyErrorExpireTime(c);
16901694
return;
16911695
}
1692-
when += commandTimeSnapshot();
1696+
when += basetime;
1697+
16931698
if (((flags & OBJ_PXAT) || (flags & OBJ_EXAT)) && checkAlreadyExpired(when)) {
16941699
set_expired = 1;
1700+
when = 0;
16951701
} else {
16961702
set_expiry = 1;
16971703
}

0 commit comments

Comments
 (0)