github.com/icyleaf/etcd-crystal

Etcd client for crystal

1 stars
0 dependents
License: Apache 2

Nothing has been indexed for 0.2.2 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  etcd:
    github: icyleaf/etcd-crystal
    version: ~> 0.2.2

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.2.2. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

Etcd

A crystal client for etcd. Heavily inspired from the ruby etcd client.

ONLY support etcd API v2 version, it means you need run etcd --enable-v2=true in etcd 3.0+ version.

Installation

Add this to your application's shard.yml:

dependencies:
  etcd:
    github: kuende/etcd-crystal

Usage

Create a client object

require "etcd"

client = Etcd.client # this will create a client against etcd server running on localhost on port 2379
client = Etcd.client("localhost:2379")
client = Etcd.client do |config|
  config.user_name = "foo"
  config.password = "bar"
end
client = Etcd.client("localhost:2379") do |config|
  config.user_name = "foo"
  config.password = "bar"
end

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

client.get("/nodes/n2").value

Delete a key

client.delete("/nodes/n1")
client.delete("/nodes/", {:recursive => true})

Compare and swap

client.compare_and_swap("/nodes/n2", {:value => "2", :prevValue => "4"}) # will set /nodes/n2 's value to 2 only if its previous value was 4

Watch a key

client.watch("/nodes/n1") # will wait till the key is changed, and return once its changed
client.watch("/nodes/n1", Etcd::Options.new, 3) # watch a key with timeout

client.watch("/nodes/n1", {:recursive => true}) # watch a directory recursive
client.watch("/nodes/n1", {:recursive => true}, 3) # watch a directory recursive with timeout

List sub keys

client.get("/nodes")

TODO

  • [ ] support SSL options
  • [ ] failover support, currently only the first server provided is used

Contributing

  1. Fork it ( https://github.com/kuende/etcd-crystal/fork )
  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 a new Pull Request