是否可以为 redis 中的所有键设置默认 ttl?
Is it possible to set default ttl for all keys in redis?
我已经阅读了 redis 配置 document 但找不到这样的选项。
我搜索并发现 "by default, the key will simply live forever"。我想急切地改变这种默认行为。
Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.
The EXPIRE family of commands is able to associate an expire to a given key, at the cost of some additional memory used by the key. When a key has an expire set, Redis will make sure to remove the key when the specified amount of time elapsed.
http://redis.io/commands/expire (again)
提前致谢!
Redis 不提供此功能 - 您必须为每个键显式设置 TTL。请注意,更新密钥会重置其 TTL,因此您必须相应地重新设置它。
我已经阅读了 redis 配置 document 但找不到这样的选项。
我搜索并发现 "by default, the key will simply live forever"。我想急切地改变这种默认行为。
Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.
The EXPIRE family of commands is able to associate an expire to a given key, at the cost of some additional memory used by the key. When a key has an expire set, Redis will make sure to remove the key when the specified amount of time elapsed.
http://redis.io/commands/expire (again)
提前致谢!
Redis 不提供此功能 - 您必须为每个键显式设置 TTL。请注意,更新密钥会重置其 TTL,因此您必须相应地重新设置它。