Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds sentinels support #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ rvm:
services:
- redis-server

before_install:
- gem install bundler

before_script:
- git submodule update --init --recursive

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,27 @@ The full list of settings is as follows.
* <b>`:database`</b> - number of database to use, default is `0`
* <b>`:namespace`</b> - prefix applied to all keys, default is `''`
* <b>`:socket`</b> - path to Unix socket if `unixsocket` is set
* <b>`:master_name`</b> - name of the master, controlling sentinels, default is `nil`
* <b>`:sentinels`</b> - array of sentinels, default is `nil`

Sentinels could be specified as follows

```rb
sentinels = [
'your_redis_host.com:26379',
'your_redis_host.com:26380',
'your_redis_host.com:26381'
]

sentinels = [
{url:'blah://sentinel5.example.net:26381'},
{url:'blah://sentinel5.example.net:26382'},
{url:'blah://sentinel5.example.net:26383'}
]
```
When you specify sentinels, you should also specify master name.
Gem em-hiredis-sentinel is used in order to get sentinel technology support
https://github.com/livehelpnow/em-hiredis-sentinel

## License

Expand Down
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