Class: Test::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/test-redis.rb,
lib/test-redis/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



17
18
19
20
# File 'lib/test-redis.rb', line 17

def initialize(options={})
  setup options
  start if !!options[:auto_start] || self.class.auto_start
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



54
55
56
# File 'lib/test-redis.rb', line 54

def base_dir
  @base_dir
end

#confObject (readonly)

Returns the value of attribute conf.



54
55
56
# File 'lib/test-redis.rb', line 54

def conf
  @conf
end

#pidObject (readonly)

Returns the value of attribute pid.



54
55
56
# File 'lib/test-redis.rb', line 54

def pid
  @pid
end

#redisObject (readonly)

Returns the value of attribute redis.



54
55
56
# File 'lib/test-redis.rb', line 54

def redis
  @redis
end

Class Method Details

.auto_startObject



9
10
11
# File 'lib/test-redis.rb', line 9

def self.auto_start
  @@auto_start ||= false
end

.auto_start=(value) ⇒ Object



13
14
15
# File 'lib/test-redis.rb', line 13

def self.auto_start=(value)
  @@auto_start = !!value
end

Instance Method Details

#infoObject



50
51
52
# File 'lib/test-redis.rb', line 50

def info
  read_info
end

#restartObject



45
46
47
48
# File 'lib/test-redis.rb', line 45

def restart
  stop
  start
end

#startObject



22
23
24
25
26
27
28
29
# File 'lib/test-redis.rb', line 22

def start
  return if @pid
  write_conf conf
  fork_redis
  at_exit { stop }
  wait_redis
  nil
end

#stop(signal = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/test-redis.rb', line 31

def stop(signal=nil)
  return unless @pid

  if File.exist? conf["pidfile"]
    realpid = File.read(conf["pidfile"]).strip.to_i
    kill realpid, signal
    FileUtils.rm_f conf["pidfile"]
  end

  kill @pid, signal

  @pid = nil
end