etcd 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -16,6 +16,54 @@ Or install it yourself as:
16
16
  $ gem install etcd
17
17
 
18
18
  ## Usage
19
+ ### Create a client object
20
+ ```ruby
21
+ client = Etcd.client # this will create a client against etcd server running on localhost on port 4001
22
+ client = Etcd.client(:port=>4002)
23
+ client = Etcd.client(:host=>'127.0.0.1', :port=>4003)
24
+ client = Etcd.client(:host=>'127.0.0.1', :port=>4003, :allow_redirect => false) # wont let you run sensitive commands on non-leader machines, default is true
25
+ ```
26
+ ### Set a key
27
+ ```ruby
28
+ client.set('/nodes/n1', 1)
29
+ # with ttl
30
+ client.set('/nodes/n2', 2, 4) # sets the ttl to 4 seconds
31
+ ```
32
+ ### Get a key
33
+ ```ruby
34
+ client.get('/nodes/n2').value
35
+
36
+ ```
37
+ ### Delete a key
38
+ ```ruby
39
+ client.delete('/nodes/n1')
40
+ ```
41
+
42
+ ### Test and set
43
+ ```ruby
44
+ client.test_and_set('/nodes/n2', 2, 4) # will set /nodes/n2 's value to 2 only if its previous value was 4
45
+
46
+ ```
47
+
48
+ ### Watch a key
49
+ ```ruby
50
+ client.watch('/nodes/n1') # will wait till the key is changed, and return once its changed
51
+ ```
52
+
53
+ ### List sub keys
54
+ ```ruby
55
+ client.get('/nodes')
56
+ ```
57
+
58
+ ### Get machines in the cluster
59
+ ```ruby
60
+ client.machines
61
+ ```
62
+
63
+ ### Get leader of the cluster
64
+ ```ruby
65
+ client.leader
66
+ ```
19
67
 
20
68
 
21
69
  ## Contributing
@@ -11,7 +11,11 @@ module Etcd
11
11
  def initialize(opts={})
12
12
  @host = opts[:host] || '127.0.0.1'
13
13
  @port = opts[:port] || 4001
14
- @allow_redirect = opts[:allow_redirect] || true
14
+ if opts.has_key?(:allow_redirect)
15
+ @allow_redirect = opts[:allow_redirect]
16
+ else
17
+ @allow_redirect = true
18
+ end
15
19
  end
16
20
 
17
21
  def version_prefix
@@ -116,11 +120,11 @@ module Etcd
116
120
  else
117
121
  Log.debug("Http error")
118
122
  Log.debug(res.body)
119
- #res.error!
120
- res
123
+ res.error!
121
124
  end
122
125
  end
123
126
 
127
+ private
124
128
  def redirect?(code)
125
129
  (code >= 300) and (code < 400)
126
130
  end
@@ -1,3 +1,3 @@
1
1
  module Etcd
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: 3406514257723307020
158
+ hash: 1991828162115001123
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: 3406514257723307020
167
+ hash: 1991828162115001123
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.23