2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ruby zkメモ

Last updated at Posted at 2014-08-25

rubyでzookeeperを使うメモ

Gemfile
gem 'zk'

インストール

bundle

or

gem install zk

APIメモ

接続
zk = ZK.new("host:port,host:port,.../chroot")
ロック
locker = zk.locker('key_name')
begin
  if ex_locker.lock!
  # do something while holding lock
  else
    raise "Oh noes, we didn't get teh lock!"
  end
ensure
  locker.unlock!
end

or 

zk.with_lock('key_name') do
  
end

etc
# node作成
zk.create(path, data, opts={})

# ephemeral mode
zk.create("/path", '', :ephemeral => true)
# => "/path"

# sequence & ephemeral
zk.create("/path", '', :sequence => true, :ephemeral => true)
# => "/path0"

# 取得
data, stat = zk.get(path, opts={})

# dataセット
zk.set(path, data, opts={})

# 存在確認
zk.exists?(path, opts={})

# 子nodeの取得
zk.children(path)
# => [ "a", "b" ]

# 削除
zk.delete("/path")
zk.delete("/path", :version => version)


# close
zk.close 
zk.close!  # pending中のイベントやthreadも強制終了

参考
https://github.com/zk-ruby/zk/blob/master/lib/zk/client/base.rb

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?