Skip to content
API for the coreos/etcd daemon
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib DRY up keys URL building Aug 4, 2013
test Initial commit Aug 3, 2013
.gitignore Initial commit Aug 3, 2013
LICENSE Initial commit Aug 3, 2013 Improved documentation for API usage Aug 4, 2013
etcd-ruby.gemspec Initial commit Aug 3, 2013


API for the coreos/etcd daemon


API for the coreos/etcd daemon


As usual, you can install it using rubygems.

$ gem install etcd-ruby


Set an etcd host for connections = "http://localhost:4001"
List machines/nodes
resp = Etcd.machines
p resp.records
Set a key/value
resp = Etcd.set "/foo/bar", "baz"
p resp.record
Set a key/value with TTL
resp = Etcd.set "/foo/bar", "baz", ttl: 5
p resp.record
Test & Set a key/value

Raises an Etcd::Error if the key does not currently exist or the given prev_value is incorrect

Etcd.set "key-does-not-exist", "baz", prev_value: "nope"
# raises Etcd::Error

Etcd.set "/foo/bar", "baz"

resp = Etcd.set "/foo/bar", "quux", prev_value: "this-value-is-wrong"
# raises Etcd::Error

resp = Etcd.set "/foo/bar", "quux", prev_value: "baz"
p resp.record
Get a value
resp = Etcd.get "/foo/bar"
p resp.record
List keys
Etcd.set "/foo/foo", "barbar"
Etcd.set "/foo/foo_dir/foo", "barbarbar"

resp = Etcd.list "/foo"
p resp.records
Delete key
Etcd.delete "/foo"
Watch for a key/value change/insertion

Watch blocks on a key until it is edited via creation, deletion, or an update. Passing an option timeout: 5 will block for the given time in seconds. If no option is given then it will block forever.

Note, the timeout is only applied to the read_timeout and will stil raise an error if it cannot connect.

resp = "/foo/message", timeout: 5
You can’t perform that action at this time.