Class: ZooMQ::Zookeeper::KeySpace
- Inherits:
-
Object
- Object
- ZooMQ::Zookeeper::KeySpace
- Defined in:
- lib/zoomq/zookeeper.rb
Instance Method Summary collapse
- #get(key) ⇒ Object (also: #[])
-
#initialize(type, zk) ⇒ KeySpace
constructor
A new instance of KeySpace.
- #path_for(key) ⇒ Object
- #set(key, value) ⇒ Object (also: #[]=)
Constructor Details
#initialize(type, zk) ⇒ KeySpace
Returns a new instance of KeySpace.
38 39 40 |
# File 'lib/zoomq/zookeeper.rb', line 38 def initialize(type, zk) @type, @zk = type, zk end |
Instance Method Details
#get(key) ⇒ Object Also known as: []
46 47 48 49 |
# File 'lib/zoomq/zookeeper.rb', line 46 def get(key) value = @zk.get(path_for(key)) rescue nil MultiJson.load(value.first) rescue nil end |
#path_for(key) ⇒ Object
42 43 44 |
# File 'lib/zoomq/zookeeper.rb', line 42 def path_for(key) "/#{@type}/#{key}" end |
#set(key, value) ⇒ Object Also known as: []=
53 54 55 56 57 58 59 |
# File 'lib/zoomq/zookeeper.rb', line 53 def set(key, value) @zk.create("/#{@type}", ignore: :node_exists) value = MultiJson.dump(value) if !@zk.create(path_for(key), value, ignore: :node_exists) @zk.set(path_for(key), value) end end |