40

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?

Vedran Juriša
  • 423
  • 1
  • 4
  • 8

3 Answers3

62

There is no default TTL. By default, keys are set to live forever.

dizzyf
  • 3,263
  • 19
  • 29
34

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

vahdet
  • 6,357
  • 9
  • 51
  • 106
7

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.

Jin Lim
  • 1,759
  • 20
  • 24