Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Gemfile.lock
*.rdb
*.un~
3 changes: 2 additions & 1 deletion faye-redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Gem::Specification.new do |s|
Dir.glob('lib/**/*.rb')

s.add_dependency 'eventmachine', '>= 0.12.0'
s.add_dependency 'em-hiredis', '>= 0.2.0'
s.add_dependency 'em-hiredis', '>= 0.3.0'
s.add_dependency 'multi_json', '>= 1.0.0'
s.add_dependency 'em-hiredis-sentinel', '>= 0.2.3'

s.add_development_dependency 'rspec'
s.add_development_dependency 'rspec-eventmachine'
Expand Down
15 changes: 10 additions & 5 deletions lib/faye/redis.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'em-hiredis'
require 'em-hiredis-sentinel'
require 'multi_json'

module Faye
Expand Down Expand Up @@ -32,8 +33,14 @@ def init
gc = @options[:gc] || DEFAULT_GC
@ns = @options[:namespace] || ''
socket = @options[:socket] || nil

if uri
sentinels = @options[:sentinels] || nil
master_name = @options[:master_name] || nil

if sentinels && master_name
@redis = EventMachine::Hiredis::Sentinel::RedisClient.new(sentinels: sentinels,
master_name: master_name).connect
@server.debug 'Redis has been initialized with sentinels'
elsif uri
@redis = EventMachine::Hiredis.connect(uri)
elsif socket
@redis = EventMachine::Hiredis::Client.new(socket, nil, auth, db).connect
Expand Down Expand Up @@ -177,7 +184,7 @@ def empty_queue(client_id)
@redis.multi
@redis.lrange(key, 0, -1)
@redis.del(key)
@redis.exec.callback do |json_messages, deleted|
@redis.exec.callback do |json_messages, deleted|
next unless json_messages
messages = json_messages.map { |json| MultiJson.load(json) }
@server.deliver(client_id, messages)
Expand Down Expand Up @@ -234,7 +241,5 @@ def with_lock(lock_name, &block)
end
end
end

end
end