Skip to content
Bare minimal ruby client for etcd
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 Ruby standard Error have a builtin method from ruby 2.1 onwards which Oct 29, 2017
.coco.yml add coco for coverage calculation Jan 12, 2014
.rspec etcd 2.0.0 port Jan 8, 2015
.rubocop.yml some rubocop fixes Jan 9, 2015
Rakefile fix rubocop error Jul 16, 2014

Built on Travis


A ruby client for etcd


Add this line to your application's Gemfile:

gem 'etcd'

And then execute:

$ bundle

Or install it yourself as:

$ gem install etcd


Create a client object

client = Etcd.client # this will create a client against etcd server running on localhost on port 4001
client = Etcd.client(port: 4002)
client = Etcd.client(host: '', port: 4003)
client = Etcd.client(:user_name => 'test', :password => 'pwd') # populates the authentication header for basic HTTP auth with user name and password (useful for proxied connections)
client = Etcd.client(host: '', port: 4003, allow_redirect: false) # wont let you run sensitive commands on non-leader machines, default is true

Create a client object to connect to a SSL etcd instance

See Etcd config to setup etcd in SSL mode.

Assuming you have these:

  • myca.crt - Your internal CAs certificate
  • my-cert.crt - The "client" cert
  • my-cert.key - The key corresponding to my-cert.crt

If you were using self signed Certs and have your own CA, You would have set -ca-file in your etcd config also to use myca.crt.

  :host => "your-etcd-host",
  :port => 443,
  :use_ssl => true,
  :ca_file => "/pathto/myca.crt",
  :ssl_cert =>"/pathto/my-cert.crt") ),
  :ssl_key =>"/etc/ssl/my-cert.key",passphrase)
#Omit passphrase if not set on your key.

Set a key

client.set('/nodes/n1', value: 1)
# with ttl
client.set('/nodes/n2', value: 2, ttl: 4)  # sets the ttl to 4 seconds

Get a key


Delete a key

client.delete('/nodes/', recursive: true)

Test and set

client.test_and_set('/nodes/n2', value: 2, prevValue: 4) # will set /nodes/n2 's value to 2 only if its previous value was 4

Watch a key'/nodes/n1') # will wait till the key is changed, and return once its changed

List sub keys


Get machines in the cluster


Get leader of the cluster


More examples and api details can be found in the wiki



  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
  6. If applicable, update the
You can’t perform that action at this time.