-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ rdoc | |
pkg | ||
|
||
## PROJECT::SPECIFIC | ||
test/config | ||
test/log | ||
test/pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'daemon_controller' | ||
require 'socket' | ||
|
||
module Memodis | ||
class LocalRedisController | ||
|
||
def self.start(config_file) | ||
new(config_file).start | ||
end | ||
|
||
attr_reader :config, :controller | ||
|
||
def initialize(config_file) | ||
config = IO.readlines(config_file) | ||
config.reject! { |l| l !~ /^(bind|port|pidfile|logfile)[ \t]?/ } | ||
config.collect! { |l| l.chomp.split(/[ \t]/) } | ||
config.flatten! | ||
config = Hash[*config] | ||
config['file'] = config_file | ||
@config = config | ||
@config.freeze | ||
|
||
@controller = DaemonController.new({ | ||
:identifier => identifier, | ||
:start_command => start_command, | ||
:ping_command => ping_command, | ||
:pid_file => pid_file, | ||
:log_file => log_file | ||
}) | ||
end | ||
|
||
def connect | ||
@controller.connect { TCPSocket.new(@config['bind'], @config['port']) } | ||
end | ||
alias :start :connect | ||
|
||
private | ||
|
||
def identifier | ||
"redis-server #{@config['file']}" | ||
end | ||
|
||
def start_command | ||
"redis-server #{@config['file']}" | ||
end | ||
|
||
def ping_command | ||
lambda { TCPSocket.new(@config['bind'], @config['port']) } | ||
end | ||
|
||
def pid_file | ||
@config['pidfile'] | ||
end | ||
|
||
def log_file | ||
@config['logfile'] | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters