O'Reilly logo

CoreOS Essentials by Rimantas Mocevicius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TTL (time to live) examples

Sometimes, it is handy to put a time to live (TTL) for a key to expire in a certain amount of time. This is useful, for example, in the case of watching a key with a 60 second TTL, from a reverse proxy. So, if the nginx fleet service has not updated the key, it will expire in 60 seconds and will be removed from etcd. Then the reverse proxy checks for it and does not find it. Hence, it will remove the nginx service from config.

Let's set a TTL of 30 seconds in this example:

  1. Type this in a terminal:
    $ etcdctl set /foo "I'm Expiring in 30 sec" --ttl 30
    I'm Expiring in 30 sec
    
  2. Verify that the key is still there:
    $ etcdctl get /foo
    I'm Expiring in 30 sec
    
  3. Check again after 30 seconds :
    $ etcdctl get /foo
    
  4. If your requested key ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required