]>
Commit | Line | Data |
---|---|---|
ed9b544e | 1 | require 'fileutils' |
2 | ||
3 | class RedisCluster | |
4 | ||
5 | def initialize(opts={}) | |
6 | opts = {:port => 6379, :host => 'localhost', :basedir => "#{Dir.pwd}/rdsrv" }.merge(opts) | |
7 | FileUtils.mkdir_p opts[:basedir] | |
8 | opts[:size].times do |i| | |
9 | port = opts[:port] + i | |
10 | FileUtils.mkdir_p "#{opts[:basedir]}/#{port}" | |
11 | File.open("#{opts[:basedir]}/#{port}.conf", 'w'){|f| f.write(make_config(port, "#{opts[:basedir]}/#{port}", "#{opts[:basedir]}/#{port}.log"))} | |
12 | system(%Q{#{File.join(File.expand_path(File.dirname(__FILE__)), "../redis/redis-server #{opts[:basedir]}/#{port}.conf &" )}}) | |
13 | end | |
14 | end | |
15 | ||
16 | def make_config(port=6379, data=port, logfile='stdout', loglevel='debug') | |
17 | config = %Q{ | |
18 | timeout 300 | |
19 | save 900 1 | |
20 | save 300 10 | |
21 | save 60 10000 | |
22 | dir #{data} | |
23 | loglevel #{loglevel} | |
24 | logfile #{logfile} | |
25 | databases 16 | |
26 | port #{port} | |
27 | } | |
28 | end | |
29 | ||
30 | end | |
31 | ||
32 | ||
33 | RedisCluster.new :size => 4 |