Class: RedisRing::Shard
- Inherits:
-
Object
- Object
- RedisRing::Shard
- Defined in:
- lib/redis_ring/shard.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#shard_config ⇒ Object
readonly
Returns the value of attribute shard_config.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #host ⇒ Object
-
#initialize(shard_config) ⇒ Shard
constructor
A new instance of Shard.
- #port ⇒ Object
- #shard_number ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(shard_config) ⇒ Shard
Returns a new instance of Shard.
7 8 9 10 |
# File 'lib/redis_ring/shard.rb', line 7 def initialize(shard_config) @shard_config = shard_config @status = :stopped end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
5 6 7 |
# File 'lib/redis_ring/shard.rb', line 5 def pid @pid end |
#shard_config ⇒ Object (readonly)
Returns the value of attribute shard_config.
5 6 7 |
# File 'lib/redis_ring/shard.rb', line 5 def shard_config @shard_config end |
Instance Method Details
#alive? ⇒ Boolean
49 50 51 |
# File 'lib/redis_ring/shard.rb', line 49 def alive? @task && @task.running? end |
#host ⇒ Object
16 17 18 |
# File 'lib/redis_ring/shard.rb', line 16 def host shard_config.host end |
#port ⇒ Object
20 21 22 |
# File 'lib/redis_ring/shard.rb', line 20 def port shard_config.port end |
#shard_number ⇒ Object
12 13 14 |
# File 'lib/redis_ring/shard.rb', line 12 def shard_number shard_config.shard_number end |
#start ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/redis_ring/shard.rb', line 34 def start if @status == :started @task.start unless @task.running? else shard_config.save @task = fork_redis_server @status = :started end end |
#status ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/redis_ring/shard.rb', line 24 def status if @status == :stopped return alive? ? :stopping : :stopped elsif @status == :started return alive? ? :running : :dead else raise RuntimeException.new("Unknown status: #{@status.inspect}") end end |
#stop ⇒ Object
44 45 46 47 |
# File 'lib/redis_ring/shard.rb', line 44 def stop @task.stop @status = :stopped end |