etcd-crystal
Etcd
A crystal client for etcd. Heavily inspired from the ruby etcd client.
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
- Fork it ( https://github.com/kuende/etcd-crystal/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Repository
etcd-crystal
Owner
Statistic
- 1
- 3
- 0
- 0
- 1
- over 3 years ago
- April 29, 2016
License
Other
Links
Synced at
Sun, 17 Nov 2024 18:20:59 GMT
Languages