API
Etcd.connect
— Function.connect(host="localhost", port=2379, version="v2")
Creates an Etcd.Client
which can then be used for making requests to an etcd cluster.
Base.get
— Method.get(cli, key, sort=false, recursive=false) -> Dict
Fetches the value for the specified key
from the etcd cluster. See the etcd API for more details.
Etcd.cad
— Method.cad(cli, key; prev_value=nothing, prev_index=-1) -> Dict
Performs an atomic compare-and-delete on the key
in the etcd cluster. See the etcd API for more details.
Etcd.cas
— Method.cas(cli, key, value; prev_value=nothing, prev_index=-1, ttl=-1) -> Dict
Performs an atomic compare-and-swap with the key
and value
on the etcd cluster. See the etcd API for more details.
Etcd.create
— Method.create(cli, key, value; ttl=-1) -> Dict
Creates a new key/value pair on the etcd cluster, asserting that the key does not already exist.
Etcd.createdir
— Method.createdir(cli, key; ttl=-1) -> Dict
Creates a new directory on the etcd cluster, asserting that the directory does not already exist.
Etcd.delete
— Method.delete(cli, key) -> Dict
Removes the key
from the etcd cluster.
Etcd.deletedir
— Method.deletedir(cli, key; recursive=false) -> Dict
Removes the directory from the etcd cluster.
Etcd.exists
— Method.exists(cli, key) -> Bool
Returns whether the key
exists in the etcd cluster.
Etcd.set
— Method.set(cli, key, value; ttl=-1, ordered=false) -> Dict
Sets the value
for the specified key
in the etcd cluster. See the etcd API for more details.
Etcd.setdir
— Method.setdir(cli, key; ttl=-1) -> Dict
Creates a directory with the specified key
on the etcd cluster.
Reference: https://github.com/coreos/etcd/blob/master/Documentation/v2/api.md#creating-directories
Etcd.update
— Method.update(cli, key, value; ttl=-1) -> Dict
Updates an existing key with a new value on the etcd cluster, asserting that the key must already exist.
Etcd.updatedir
— Method.updatedir(cli, key; ttl=-1) -> Dict
Updates the name of a direcotry on the etcd cluster, asserting that the directory already exists.
Etcd.watch
— Method.watch(f, cli, key; wait_index=-1, recursive=false)
Creates an asynchronous Task
which watches the key
on the etcd cluster and runs function f
on the response. See the etcd API for more details.
Etcd.watchloop
— Function.watchloop(f, cli, key, [p]; wait_index=-1, recursive=false)
Creates an asynchrous Task
which continously watches the key
on the etcd cluster and runs function f
on the response. The predicate function p
represents a termination condition to exit the loop. See the etcd API for more details.
Etcd.machines
— Method.machines(cli) -> Array
Returns an array of machines (socket addresses) in the cluster.
Etcd.stats
— Method.stats(cli, stats_type) -> Dict
Fetches any stats from the cluster (stats_type
may be "store", "self" or "leader") See the etcd API for more details.
Etcd.leader
— Method.leader(cli) -> Dict
Fetchers the stats for the leader of the etcd cluster. See the etcd API for more details.
Etcd.members
— Method.members(cli) -> Dict
Returns a dict (id, member) of members in the etcd cluster. See the etcd API for more details.
Etcd.request
— Function.request(f, uri, opts; n=5, max_delay=10.0)
Executes the HTTP request f
with the given uri
and opts
and returns the response body. JSON responses are parsed with Requests.json
otherwise a String
is returned. For failed HTTP or etcd requests an HTTPError
or EtcdError
is thrown respectively.
Arguments
f::Function
: a validRequests
method (e.g.,Requests.get
)uri::String
: the HTTP uriopts::Dict
: a set of options to be passed tof
with the keywordquery
n=5
: the number of retry attempts for the requestmax_delay=10.0
: delay in seconds between each retry attempt
Throws
HTTPError
: when the HTTP response has a status code >= 400EtcdError
: when the HTTP response body contains "errorCode" which signifies an etcd error
Returns
Dict
: for most etcd response (the parsed json HTTP response body)Array
: some etcd responses return a list vs dict when parse the json HTTP response bodyString
: all non-json response bodies
Etcd.HTTPError
— Type.HTTPError <: Exception
Wraps a Requests.Response
when the response status is >= 400.
Etcd.EtcdError
— Type.EtcdError <: Exception
Wraps an etcd response Dict
when the response contains an "errorCode"
.
Etcd.install
— Function.install(force=true)
Downloads and installs a local etcd server (mostly for testing).
Etcd.start
— Function.start(timeout=-1) -> Future
Starts up the local etcd server (mostly for testing). The timeout
specifies a number of seconds to run the server for (using timeout
or gtimeout
).