Class: RedisRing::Client::RingMetaData

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_ring/client/ring_meta_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zookeeper_addr, cluster_name) ⇒ RingMetaData

Returns a new instance of RingMetaData.



10
11
12
13
# File 'lib/redis_ring/client/ring_meta_data.rb', line 10

def initialize(zookeeper_addr, cluster_name)
  @zookeeper_addr = zookeeper_addr
  @cluster_name = cluster_name
end

Instance Attribute Details

#cluster_nameObject (readonly)

Returns the value of attribute cluster_name.



8
9
10
# File 'lib/redis_ring/client/ring_meta_data.rb', line 8

def cluster_name
  @cluster_name
end

#zookeeperObject (readonly)

Returns the value of attribute zookeeper.



8
9
10
# File 'lib/redis_ring/client/ring_meta_data.rb', line 8

def zookeeper
  @zookeeper
end

#zookeeper_addrObject (readonly)

Returns the value of attribute zookeeper_addr.



8
9
10
# File 'lib/redis_ring/client/ring_meta_data.rb', line 8

def zookeeper_addr
  @zookeeper_addr
end

Instance Method Details

#reload!Object



15
16
17
18
19
20
21
# File 'lib/redis_ring/client/ring_meta_data.rb', line 15

def reload!
  json = get_shards_json_string
  hash = JSON.parse(json)

  @ring_size = hash['ring_size']
  @shards = (0...@ring_size).map{|n| ShardMetaData.from_json(hash['shards'][n.to_s])}
end

#ring_sizeObject



23
24
25
26
27
# File 'lib/redis_ring/client/ring_meta_data.rb', line 23

def ring_size
  reload! if should_reload?

  return @ring_size
end

#shard(shard_number) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/redis_ring/client/ring_meta_data.rb', line 29

def shard(shard_number)
  reload! if should_reload?

  unless shard_number >= 0 && shard_number < ring_size
    raise UnknownShardError.new("Shard number invalid: #{shard_number}. Ring size: #{ring_size}")
  end

  return @shards[shard_number]
end