I am learning about TTL and trying some examples. But when I set a specific large number the key is not created (or at least it is deleted so fast) like below.

127.0.0.1:6379> set sullyvan nunes EX 10000000000000000
OK
127.0.0.1:6379> get sullyvan
(nil)

It is worth to point out a larger and a fewer number works fine.

127.0.0.1:6379> set sullyvan nunes EX 100000000000000000
OK
127.0.0.1:6379> get sullyvan
"nunes"
127.0.0.1:6379> set sullyvan nunes EX 1000000000000000
OK
127.0.0.1:6379> get sullyvan
"nunes"

I am using macOS Mojave 10.14.6 and Redis-cli version: 5.0.7

Could someone help me to understand this behavior?

Comment From: patpatbear

@sullyvannunes this is caused by long long overflow, not an issue, you should specify smaller TTL.

TTL is represented by long long MILLISECOND inside redis, set sullyvan nunes EX 100000000000000000 means sullyvan will be expired 100000000000000000 SECONDS, i.e. 100000000000000000000 milliseconds, which exceeds range of LONG_LONG_MAX 9223372036854775807.

Comment From: filipecosta90

@sullyvannunes this is caused by long long overflow, not an issue, you should specify smaller TTL.

TTL is represented by long long MILLISECOND inside redis, set sullyvan nunes EX 100000000000000000 means sullyvan will be expired 100000000000000000 SECONDS, i.e. 100000000000000000000 milliseconds, which exceeds range of LONG_LONG_MAX 9223372036854775807.

hi there @patpatbear if we specify the expire time in milliseconds this will never happen due to the overflow guard on getLongLongFromObjectOrReply->getLongLongFromObject->string2ll See example bellow

127.0.0.1:6379> SET a b PX 9223372036854775806
OK
127.0.0.1:6379> SET a b PX 9223372036854775807
(error) ERR value is not an integer or out of range
127.0.0.1:6379> SET a b EX 9223372036854775807
OK

The issue here is that we dont check for overflow when we internally convert from seconds to milliseconds. #6801 fixes it.

Comment From: patpatbear

@filipecosta90 @sullyvannunes , oops , i missed the range check.

Comment From: sullyvannunes

got it! Thanks @filipecosta90 @patpatbear

Comment From: oranagra

why would someone want to expire a key in 317097919 years?

Comment From: oranagra

fixed by #8287