Class: RedisRing::Shard

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pidObject (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/redis_ring/shard.rb', line 5

def pid
  @pid
end

#shard_configObject (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

Returns:

  • (Boolean)


49
50
51
# File 'lib/redis_ring/shard.rb', line 49

def alive?
  @task && @task.running?
end

#hostObject



16
17
18
# File 'lib/redis_ring/shard.rb', line 16

def host
  shard_config.host
end

#portObject



20
21
22
# File 'lib/redis_ring/shard.rb', line 20

def port
  shard_config.port
end

#shard_numberObject



12
13
14
# File 'lib/redis_ring/shard.rb', line 12

def shard_number
  shard_config.shard_number
end

#startObject



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

#statusObject



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

#stopObject



44
45
46
47
# File 'lib/redis_ring/shard.rb', line 44

def stop
  @task.stop
  @status = :stopped
end