简体   繁体   中英

Is it possible to set default ttl for all keys in redis?

I've read redis config document but can't find such option.

I've searched and found that "by default, the key will simply live forever". And I want to change this default behavior eagerly.

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)

Thanks in advance !

Redis does not provide this ability - you'll have to explicitly set a TTL for every key. Note that updating a key resets its TTL, so you'll have to re-set it accordingly.

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