forked from emaland/zookeeper_client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
53 lines (35 loc) · 1.47 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
zookeeper
An interface to the Zookeeper distributed configuration server.
== License
Copyright 2008 Phillip Pearson, and 2010 Twitter, Inc. Licensed under the MIT License. See the included LICENSE file. Portions copyright 2008-2010 the Apache Software Foundation, licensed under the Apache 2 license, and used with permission.
== Install
sudo gem install zookeeper
== Usage
Connect to a server:
require 'rubygems'
require 'zookeeper'
z = Zookeeper.new("localhost:2181")
Create, set and read nodes:
z.create("/bacon", "text to be stored in the new node", 0)
data, stat = z.get("/bacon")
# => ["text to be stored in the new node"...]
z.set("/bacon", "an entirely different line of text", stat.version)
z.set("/bacon", "this won't work", stat.version)
# CZookeeper::BadVersionError: expected version does not match actual version
data, stat = z.get("/bacon")
# => ["an entirely different line of text"...]
z.delete("/bacon", stat.version)
Create ephemeral and sequence nodes:
z.create("/parent", "parent node", 0)
z.create("/parent/test-",
"an ordered ephemeral node",
Zookeeper::EPHEMERAL | Zookeeper::SEQUENCE)
# => "/parent/test-0"
z.create("/parent/test-",
"an ordered ephemeral node",
Zookeeper::EPHEMERAL | Zookeeper::SEQUENCE)
# => "/parent/test-1"
Acquire locks:
z.try_acquire "/parent/lock-", "content for the lock file" do |have_lock|
puts have_lock ? "we have the lock" : "we don't have the lock"
end