forked from stevegraham/slanger
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue where a new redis connection was made for each api request
- Loading branch information
1 parent
f127b9b
commit 50f2227
Showing
6 changed files
with
34 additions
and
12 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
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 |
---|---|---|
@@ -1,3 +1,20 @@ | ||
require 'forwardable' | ||
|
||
module Slanger | ||
Redis = EM::Hiredis.connect if EM.reactor_running? | ||
end | ||
module Redis | ||
extend Forwardable | ||
|
||
def_delegator :publisher, :publish | ||
def_delegators :subscriber, :on, :subscribe | ||
|
||
private | ||
def publisher | ||
@publisher ||= EM::Hiredis.connect | ||
end | ||
|
||
def subscriber | ||
@subscriber ||= EM::Hiredis.connect | ||
end | ||
extend self | ||
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
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
require 'bundler/setup' | ||
|
||
require 'eventmachine' | ||
require 'em-hiredis' | ||
require 'rack' | ||
|
||
module Slanger; end | ||
|
||
EM.run do | ||
File.tap do |f| | ||
Dir[f.expand_path(f.join(f.dirname(__FILE__),'lib', 'slanger', '*.rb'))].reverse_each { |file| require file } | ||
Dir[f.expand_path(f.join(f.dirname(__FILE__),'lib', 'slanger', '*.rb'))].each do |file| | ||
Slanger.autoload File.basename(file, '.rb').classify, file | ||
end | ||
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