简体   繁体   中英

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?

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM