mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
feat(README): add directory TTL documentation
This commit is contained in:
parent
f66bd1689d
commit
bb64e7b6e5
51
README.md
51
README.md
@ -226,8 +226,7 @@ If the TTL has expired, the key will be deleted, and you will be returned a 100.
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Waiting for a change
|
||||
### Waiting for a change
|
||||
|
||||
We can watch for a change on a key and receive a notification by using long polling.
|
||||
This also works for child keys by passing `recursive=true` in curl.
|
||||
@ -273,6 +272,54 @@ curl -L http://127.0.0.1:4001/v2/keys/foo?wait=true\&waitIndex=7
|
||||
The watch command returns immediately with the same response as previous.
|
||||
|
||||
|
||||
### Using a directory TTL
|
||||
|
||||
Like keys, directories in etcd can be set to expire after a specified number of seconds.
|
||||
You can do this by setting a TTL (time to live) on a directory when it is created with a `PUT`:
|
||||
|
||||
```sh
|
||||
curl -L http://127.0.0.1:4001/v2/keys/dir -XPUT -d ttl=30 -d dir=true
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "set",
|
||||
"node": {
|
||||
"createdIndex": 17,
|
||||
"dir": true,
|
||||
"expiration": "2013-12-11T10:37:33.689275857-08:00",
|
||||
"key": "/newdir",
|
||||
"modifiedIndex": 17,
|
||||
"ttl": 30
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The directories TTL can be refreshed by making an update.
|
||||
You can do this by making a PUT with `prevExist=true` and a new TTL.
|
||||
|
||||
```sh
|
||||
curl -L http://127.0.0.1:4001/v2/keys/dir -XPUT -d ttl=30 -d dir=true -d prevExist=true
|
||||
```
|
||||
|
||||
Keys that are under this directory work as usual, but when the directory expires a watcher on a key under the directory will get an expire event:
|
||||
|
||||
```sh
|
||||
curl -X GET http://127.0.0.1:4001/v2/keys/dir/asdf\?consistent\=true\&wait\=true
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "expire",
|
||||
"node": {
|
||||
"createdIndex": 8,
|
||||
"key": "/dir",
|
||||
"modifiedIndex": 15
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Atomic Compare-and-Swap (CAS)
|
||||
|
||||
Etcd can be used as a centralized coordination service in a cluster and `CompareAndSwap` is the most basic operation to build distributed lock service.
|
||||
|
Loading…
x
Reference in New Issue
Block a user