【问题标题】:Is it possible to set default ttl for all keys in redis?是否可以为redis中的所有键设置默认ttl?
【发布时间】:2015-08-10 02:09:10
【问题描述】:

我已阅读 redis config document 但找不到这样的选项。

我搜索并发现“默认情况下,密钥将永远存在”。我想急切地改变这种默认行为。

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 hiredis


    【解决方案1】:

    Redis 不提供此功能 - 您必须为每个键显式设置 TTL。请注意,更新密钥会重置其 TTL,因此您必须相应地重新设置它。

    【讨论】:

    • 虽然这在 redis 中是不可能的,但任何语言包装器都可以通过在连接存在的客户端实现上使用方法来保持默认 ttl 来填充它
    猜你喜欢
    • 1970-01-01
    • 2019-08-24
    • 2014-10-15
    • 1970-01-01
    • 2021-07-22
    • 2019-04-05
    • 2014-10-26
    • 2011-10-15
    • 2021-05-12
    相关资源
    最近更新 更多