redis-slave 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/redis/slave.rb CHANGED
@@ -6,29 +6,33 @@ require "redis/slave/version"
6
6
 
7
7
  class Redis::Slave
8
8
 
9
- attr_reader :process, :master_host, :master_port, :host, :port, :logfile, :dir
9
+ attr_reader :process, :options
10
10
 
11
11
  def initialize options={}
12
- @master_host = options[:master_host] || '127.0.0.1'
13
- @master_port = options[:master_port] || '6379'
14
- @host = options[:host] || '127.0.0.1'
15
- @port = options[:port] || find_available_port
16
- @logfile = options[:logfile] || Tempfile.new('redis-slave-logfile').path
17
- @dir = options[:dir] || Dir.tmpdir
12
+ @options = options;
13
+ options[:master] ||= {}
14
+ options[:slave] ||= {}
15
+ options[:master][:host] ||= '127.0.0.1'
16
+ options[:master][:port] ||= '6379'
17
+ options[:slave ][:host] ||= '127.0.0.1'
18
+ options[:slave ][:port] ||= find_available_port
19
+ options[:logfile] ||= Tempfile.new('redis-slave-logfile').path
20
+ options[:dir] ||= Dir.tmpdir
18
21
  end
19
22
 
20
- def redis_master
21
- ::Redis.new(:host => @master_host, :port => @master_port)
23
+ def master
24
+ ::Redis.new(options[:master])
22
25
  end
23
26
 
24
- def redis_slave
27
+ def slave
25
28
  start!
26
- ::Redis.new(:host => @host, :port => @port)
29
+ ::Redis.new(options[:slave])
27
30
  end
28
31
 
29
- def redis
30
- Balancer.new(redis_master, redis_slave)
32
+ def balancer
33
+ Balancer.new(master, slave)
31
34
  end
35
+ alias_method :redis, :balancer
32
36
 
33
37
  def started?
34
38
  !!@started
@@ -47,17 +51,17 @@ class Redis::Slave
47
51
 
48
52
  def config
49
53
  <<-CONFIG
50
- slaveof #{master_host} #{master_port}
54
+ slaveof #{options[:master][:host]} #{options[:master][:port]}
51
55
  slave-serve-stale-data yes
52
56
  daemonize no
53
- bind #{host}
54
- port #{port}
55
- logfile #{logfile}
57
+ bind #{options[:slave][:host]}
58
+ port #{options[:slave][:port]}
59
+ logfile #{options[:logfile]}
56
60
  databases 1
57
61
  save 900 1
58
62
  rdbcompression yes
59
63
  dbfilename dump.rdb
60
- dir #{dir}
64
+ dir #{options[:dir]}
61
65
  appendonly no
62
66
  appendfsync no
63
67
  appendfsync everysec
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class Slave
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-slave
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jared Grippe