Class: RedisRing::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slave_rpc, host, port) ⇒ Node

Returns a new instance of Node.



21
22
23
24
25
# File 'lib/redis_ring/node.rb', line 21

def initialize(slave_rpc, host, port)
  @slave_rpc = slave_rpc
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



19
20
21
# File 'lib/redis_ring/node.rb', line 19

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



19
20
21
# File 'lib/redis_ring/node.rb', line 19

def port
  @port
end

#slave_rpcObject (readonly)

Returns the value of attribute slave_rpc.



19
20
21
# File 'lib/redis_ring/node.rb', line 19

def slave_rpc
  @slave_rpc
end

Instance Method Details

#available_shardsObject



52
53
54
# File 'lib/redis_ring/node.rb', line 52

def available_shards
  @available_shards ||= {}
end

#joined?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/redis_ring/node.rb', line 34

def joined?
  @joined
end

#running_shardsObject



48
49
50
# File 'lib/redis_ring/node.rb', line 48

def running_shards
  @running_shards ||= []
end

#start_shard(shard_number) ⇒ Object



38
39
40
41
# File 'lib/redis_ring/node.rb', line 38

def start_shard(shard_number)
  running_shards << shard_number
  slave_rpc.start_shard(shard_number)
end

#stop_shard(shard_number) ⇒ Object



43
44
45
46
# File 'lib/redis_ring/node.rb', line 43

def stop_shard(shard_number)
  running_shards.delete(shard_number)
  slave_rpc.stop_shard(shard_number)
end

#update_status!Object



27
28
29
30
31
32
# File 'lib/redis_ring/node.rb', line 27

def update_status!
  status_hash = slave_rpc.status
  @joined = status_hash["joined"]
  @running_shards = status_hash["running_shards"] || []
  @available_shards = keys_to_i(status_hash["available_shards"] || {})
end