|
|
@@ -317,6 +317,7 @@ curl -X POST http://127.0.0.1:4001/v2/keys/queue -d value=Job2
|
|
|
|
|
|
[lockmod]: #lock
|
|
|
|
|
|
+
|
|
|
### Using a directory TTL
|
|
|
|
|
|
Like keys, directories in etcd can be set to expire after a specified number of seconds.
|
|
|
@@ -446,6 +447,27 @@ The response should be
|
|
|
|
|
|
We successfully changed the value from "one" to "two" since we gave the correct previous value.
|
|
|
|
|
|
+### Creating Directories
|
|
|
+
|
|
|
+In most cases directories for a key are automatically created.
|
|
|
+But, there are cases where you will want to create a directory or remove one.
|
|
|
+
|
|
|
+Creating a directory is just like a key only you cannot provide a value and must add the `dir=true` parameter.
|
|
|
+
|
|
|
+```sh
|
|
|
+curl -L http://127.0.0.1:4001/v2/keys/dir -XPUT -d dir=true
|
|
|
+```
|
|
|
+```json
|
|
|
+{
|
|
|
+ "action": "set",
|
|
|
+ "node": {
|
|
|
+ "createdIndex": 30,
|
|
|
+ "dir": true,
|
|
|
+ "key": "/dir",
|
|
|
+ "modifiedIndex": 30
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
### Listing a directory
|
|
|
|
|
|
@@ -533,14 +555,31 @@ curl -L http://127.0.0.1:4001/v2/keys/?recursive=true
|
|
|
```
|
|
|
|
|
|
|
|
|
-### Deleting a directory
|
|
|
+### Deleting a Directory
|
|
|
|
|
|
Now let's try to delete the directory `/foo_dir`.
|
|
|
|
|
|
-To delete a directory, we must add `recursive=true`.
|
|
|
+You can remove an empty directory using the `DELETE` verb and the `dir=true` parameter.
|
|
|
|
|
|
```sh
|
|
|
-curl -L http://127.0.0.1:4001/v2/keys/foo_dir?recursive=true -XDELETE
|
|
|
+curl -L -X DELETE 'http://127.0.0.1:4001/v2/keys/dir?dir=true'
|
|
|
+```
|
|
|
+```json
|
|
|
+{
|
|
|
+ "action": "delete",
|
|
|
+ "node": {
|
|
|
+ "createdIndex": 30,
|
|
|
+ "dir": true,
|
|
|
+ "key": "/dir",
|
|
|
+ "modifiedIndex": 31
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+To delete a directory that holds keys, you must add `recursive=true`.
|
|
|
+
|
|
|
+```sh
|
|
|
+curl -L http://127.0.0.1:4001/v2/keys/dir?recursive=true -XDELETE
|
|
|
```
|
|
|
|
|
|
```json
|
|
|
@@ -549,7 +588,7 @@ curl -L http://127.0.0.1:4001/v2/keys/foo_dir?recursive=true -XDELETE
|
|
|
"node": {
|
|
|
"createdIndex": 10,
|
|
|
"dir": true,
|
|
|
- "key": "/foo_dir",
|
|
|
+ "key": "/dir",
|
|
|
"modifiedIndex": 11
|
|
|
}
|
|
|
}
|