Class: RedisRing::Node
- Inherits:
-
Object
- Object
- RedisRing::Node
- Defined in:
- lib/redis_ring/node.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#slave_rpc ⇒ Object
readonly
Returns the value of attribute slave_rpc.
Instance Method Summary collapse
- #available_shards ⇒ Object
-
#initialize(slave_rpc, host, port) ⇒ Node
constructor
A new instance of Node.
- #joined? ⇒ Boolean
- #running_shards ⇒ Object
- #start_shard(shard_number) ⇒ Object
- #stop_shard(shard_number) ⇒ Object
- #update_status! ⇒ Object
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
19 20 21 |
# File 'lib/redis_ring/node.rb', line 19 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
19 20 21 |
# File 'lib/redis_ring/node.rb', line 19 def port @port end |
#slave_rpc ⇒ Object (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_shards ⇒ Object
52 53 54 |
# File 'lib/redis_ring/node.rb', line 52 def available_shards @available_shards ||= {} end |
#joined? ⇒ Boolean
34 35 36 |
# File 'lib/redis_ring/node.rb', line 34 def joined? @joined end |
#running_shards ⇒ Object
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 |