5

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 !

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
oyjh
  • 1,248
  • 1
  • 9
  • 20

1 Answers1

10

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.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • Whilst this is not possible in redis, any language wrapper could polyfill this by having methods on the Client implementation where the connection lives to persist a default ttl – MrMesees Nov 08 '19 at 11:39