I can't find anywhere online what is default TTL in Redis. I know that I can set TTL for specific SET, but don't know what is default TTL. Can someone tell me what default time to live is in Redis?
3 Answers
There is no default TTL. By default, keys are set to live forever.

- 3,263
- 19
- 29
-
2That's all i wanted to know. Thank you a lot. – Vedran Juriša Mar 06 '18 at 14:58
-
what if I set this value to 0 ? – Simon Su Feb 25 '19 at 08:54
-
1@SimonSu It deletes the key. – dizzyf Feb 25 '19 at 16:56
The keys with no expiration time set will not expire.
If you mean TTL command specifically, starting with v2.8, it will return -2 if no EXPIRE
value is set.
Edit: Itamar Haber's comment is true, I recalled false: There is no such setting in redis config for a global TTL. So I deleted the part about that.
Edit2: Also see the link to the official docs about default expiration of keys here: https://redis.io/commands/expire#appendix-redis-expires

- 6,357
- 9
- 51
- 106
-
1
-
is there somewhere in the docs that state this ? I'm happy to have found the answer here, but I was hoping to find it in the docs. – aaaaaa Nov 20 '19 at 03:11
I suppose value set to '-1' by default which means forever.
127.0.0.1:6379> set datakey "my-data"
OK
127.0.0.1:6379> TTL datakey
(integer) -1
127.0.0.1:6379>
REDIS Docs says
Starting with Redis 2.8 the return value in case of error changed:
The command returns -2 if the key does not exist. The command returns -1 if the key exists but has no associated expire.

- 1,759
- 20
- 24