Vedran Juriša
Vedran Juriša

Reputation: 513

What's default TTL in Redis?

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?

Upvotes: 49

Views: 72647

Answers (3)

Jin Lim
Jin Lim

Reputation: 2152

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.

Upvotes: 9

vahdet
vahdet

Reputation: 6749

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

Upvotes: 35

dizzyf
dizzyf

Reputation: 3693

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

Upvotes: 75

Related Questions