简体   繁体   English

Redis 中的默认 TTL 是多少?

[英]What's default TTL in Redis?

I can't find anywhere online what is default TTL in Redis.我在网上找不到什么是 Redis 中的默认 TTL。 I know that I can set TTL for specific SET, but don't know what is default TTL.我知道我可以为特定的 SET 设置 TTL,但不知道什么是默认 TTL。 Can someone tell me what default time to live is in Redis?有人能告诉我 Redis 的默认生存时间是多少吗?

There is no default TTL.没有默认的 TTL。 By default, keys are set to live forever.默认情况下,密钥设置为永远存在。

The keys with no expiration time set will not expire.没有设置过期时间的key不会过期。

If you mean TTL command specifically, starting with v2.8, it will return -2 if no EXPIRE value is set.如果你特指TTL 命令,从 v2.8 开始,如果没有设置EXPIRE值,它将返回 -2。

Edit: Itamar Haber's comment is true, I recalled false: There is no such setting in redis config for a global TTL.编辑:Itamar Haber 的评论是正确的,我记得是错误的:在全局 TTL 的redis 配置中没有这样的设置。 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 Edit2:另请参阅有关密钥默认过期的官方文档链接: https ://redis.io/commands/expire#appendix-redis-expires

I suppose value set to '-1' by default which means forever.我假设值默认设置为“-1”,这意味着永远。

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 REDIS 文档说


Starting with Redis 2.8 the return value in case of error changed:从 Redis 2.8 开始,发生错误时的返回值发生了变化:

The command returns -2 if the key does not exist.如果密钥不存在,则该命令返回 -2。 The command returns -1 if the key exists but has no associated expire.如果密钥存在但没有关联的过期时间,则该命令返回 -1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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