redis-slave 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/redis/slave.rb +22 -18
- data/lib/redis/slave/version.rb +1 -1
- metadata +3 -3
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, :
|
9
|
+
attr_reader :process, :options
|
10
10
|
|
11
11
|
def initialize options={}
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
21
|
-
::Redis.new(:
|
23
|
+
def master
|
24
|
+
::Redis.new(options[:master])
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
27
|
+
def slave
|
25
28
|
start!
|
26
|
-
::Redis.new(:
|
29
|
+
::Redis.new(options[:slave])
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
30
|
-
Balancer.new(
|
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 #{
|
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
|
data/lib/redis/slave/version.rb
CHANGED
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jared Grippe
|