redis-doc icon indicating copy to clipboard operation
redis-doc copied to clipboard

[EXPIRE] What is the maximum of expire value

Open stories2 opened this issue 3 years ago • 4 comments

Hello, i want to set maximum of ttl using expire command.

So, i want to know what is the maximum of value can pass to expire command.

I know the command PERSIST can make no expire.

But i have personal reason to use expire command not a PERSIST.

I'm using redis 3.2.10

stories2 avatar Jan 16 '23 04:01 stories2

Hello @stories2

It depends.

EXPIRE will accept as a maximum TTL value the number of seconds remaining until some time in the year 2038. If you were to run it on Jan 1st, 1970 at 00:00:00Z, you could have used the value of 9223372036854775 seconds as a maximum. Because time keeps moving, using EXPIRE for that is hard.

Instead, consider using EXPIREAT and the the value of 9223372036854775 to set the TTL to the max.

itamarhaber avatar Jan 16 '23 12:01 itamarhaber

@itamarhaber Then i have one more question. What is 9223372036854775? Is it (2^63-1 millisec / 1000) => sec ?

stories2 avatar Jan 16 '23 13:01 stories2

Hi, @stories2 You're right. Actully. 1] pexpire uses miliseconds. -> https://redis.io/commands/pexpire/ 2] and It uses LLONG (Signed Value) -> so it is 2^63 - 1 (instead of 2^64 -1)

clark-lt avatar Jan 16 '23 15:01 clark-lt

Thx everyone.

stories2 avatar Jan 16 '23 15:01 stories2