Class: Redis::Server
- Inherits:
-
Object
- Object
- Redis::Server
- Defined in:
- lib/redis/server/version.rb,
lib/redis/server.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Instance Method Summary collapse
- #connect(options = {}) ⇒ Object
- #connection ⇒ Object
-
#find_available_port ⇒ Object
copied from capybara-1.1.2.
-
#initialize(config = {}) ⇒ Server
constructor
A new instance of Server.
- #save ⇒ Object
- #start ⇒ Object
- #start! ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Server
Returns a new instance of Server.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/redis/server.rb', line 12 def initialize config={} @config = Redis::Server::Config.new(config) @config[:'slave-serve-stale-data'] ||= "no" @config[:'daemonize'] ||= "no" @config[:'bind'] ||= "127.0.0.1" @config[:'port'] ||= "#{find_available_port}" @config[:'logfile'] ||= Tempfile.new('redis-server-logfile').path @config[:'save'] ||= "900 1" @config[:'rdbcompression'] ||= "yes" @config[:'dbfilename'] ||= "redis_server.rdb" @config[:'dir'] ||= Dir.tmpdir @config[:'appendonly'] ||= "no" @config[:'appendfsync'] ||= "no" @config[:'appendfsync'] ||= "everysec" @config[:'no-appendfsync-on-rewrite'] ||= "yes" end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/redis/server.rb', line 10 def config @config end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
10 11 12 |
# File 'lib/redis/server.rb', line 10 def process @process end |
Instance Method Details
#connect(options = {}) ⇒ Object
60 61 62 63 64 |
# File 'lib/redis/server.rb', line 60 def connect ={} [:host] ||= config[:bind] [:port] ||= config[:port] Redis.new() end |
#connection ⇒ Object
56 57 58 |
# File 'lib/redis/server.rb', line 56 def connection @connection ||= connect if started? end |
#find_available_port ⇒ Object
copied from capybara-1.1.2
71 72 73 74 75 76 |
# File 'lib/redis/server.rb', line 71 def find_available_port server = TCPServer.new('127.0.0.1', 0) server.addr[1] ensure server.close if server end |
#save ⇒ Object
48 49 50 |
# File 'lib/redis/server.rb', line 48 def save connection.save if connection end |
#start ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/redis/server.rb', line 29 def start return if started? @process = ChildProcess.new('redis-server','-') process.duplex = true process.start at_exit{ save stop } process.io.stdin.puts config.to_s process.io.stdin.close @started = process.alive? end |
#start! ⇒ Object
43 44 45 46 |
# File 'lib/redis/server.rb', line 43 def start! start started? or raise "failed to start redis server" end |
#started? ⇒ Boolean
66 67 68 |
# File 'lib/redis/server.rb', line 66 def started? process && process.alive? end |
#stop ⇒ Object
52 53 54 |
# File 'lib/redis/server.rb', line 52 def stop process.stop if started? end |