keys: List a key or all keys

Description Arguments Value Methods Headers Setting a key from file Examples

Description

List a key or all keys

Arguments

key

(character) A key name. Optional.

value

Any object to store. Required for create, update, and delete functions

recursive

Whether to do recursive something???

sorted

Whether to return sorted or not.

prevValue

(character) Previous value to match against.

prevIndex

(integer) Previous index to match against.

ttl

(integer) Seconds after which the key will be removed.

dir

(logical) Whether to crate or delete a directory or not

wait

(logical) Whether to wait or not for a key change. Deafult: FALSE

wait_index

(integer) Index to wait until

...

Further args passed on to GET

Value

All return a list, with named slots 'action' and 'node'. If the key previously existed, or is deleted, or updated, you get an addition slot 'prevNode'. The action slot tells you what action you took. the 'node' slot gives the key name, its value, a 'modifiedIndex' and a 'createdIndex'

Methods

Headers

You can get header info on requests via curl options like key("/mykey", config = verbose()), but make sure to load httr first. Headers include in particular three useful ones that provide global information about the etcd cluster that serviced a request:

Setting a key from file

Note that setting a key from a file is not working yet.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
## Not run: 
# make a client
cli <- etcd()

# Make a key
cli$create(key="/mykey", value="this is awesome")
cli$create(key="/things", value="and stuff!")
## use ttl (expires after ttl seconds)
cli$create(key="/stuff", value="tables", ttl=10)

# Make a directory
cli$create(key="/mydir", dir = TRUE)
# List a directory
cli$key("/mydir")
# Make a key inside a directory
cli$create("/mydir/key1", value = "foo")
cli$create("/mydir/key2", value = "bar")
# List again, now with two keys
cli$key("/mydir")
# Delete a directory
cli$delete(key="/mydir", dir = TRUE)

# Update a key
cli$update(key="/things", value="and stuff! and more things")

# Create an in-order key
cli$create_inorder("/queue", "thing1")
cli$create_inorder("/queue", "thing2")
cli$create_inorder("/queue", "thing3")
cli$key("/queue", sorted = TRUE, recursive = TRUE)

# List all keys
cli$keys()
cli$keys(sorted = TRUE)
cli$keys(recursive = TRUE)
cli$keys(sorted = TRUE, recursive = TRUE)

# List a single key
cli$key("/mykey")
cli$key("/things")

# Waiting
## Wait for a change via long-polling
## in another R session, load etseed, then run the 2nd line of code
# cli$key("/anewkey", wait = TRUE)
# cli$create("/anewkey", "hey from another R session")
## Wait for change from cleared event index
# cli$key("/anewkey", wait = TRUE, wait_index = 7)

# Delete a key
cli$create("/hello", "world")
cli$delete("/hello")
## Delete only if matches previous value, fails
cli$delete("/things", prevValue="two")
## Delete only if matches previous index
### Fails
cli$delete("/things", prevIndex=1)
### Works
cli$delete("/things", prevIndex=13)

# curl options
library("httr")
cli$keys(config = verbose())

# Hidden keys
## Create a hidden key using "_" at beginning
cli$create("/_message", "my hidden key")
## A key that's not hidden
cli$create("/message", "my un-hidden key")
## Call to root directory doesn't show the hidden key
cli$keys()

# Set a key from a file
# cat("hello\nworld", file = "myfile.txt")
# cli$create("/myfile", file = file)

## End(Not run)

etseed documentation built on May 2, 2019, 10:20 a.m.