Skip to content

Commit

Permalink
Support connecting to redis sentinel.
Browse files Browse the repository at this point in the history
* Expose `url` and `sentinels` options.
* Connect to sentinel if options are passed.
  • Loading branch information
jmcarp committed Jul 10, 2016
1 parent 5e36d24 commit 45ca8e5
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/logstash/outputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base
# The Redis database number.
config :db, :validate => :number, :default => 0

# Redis master URL, if using Sentinel. For example: `redis://redis-cluster`.
config :url, :valiate => :string, :default => ""

# The hostname(s) of your Redis Sentinel server(s), if using Sentinel.
# Values are formatted like the `host` setting above.
config :sentinels, :validate => :array, :default => []

# Redis initial connection timeout in seconds.
config :timeout, :validate => :number, :default => 5

Expand Down Expand Up @@ -200,6 +207,13 @@ def close

private
def connect
params = if @sentinels.size then params_sentinel else params_redis end
@logger.debug(params)

Redis.new(params)
end

def params_redis
@current_host, @current_port = @host[@host_idx].split(':')
@host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1

Expand All @@ -219,8 +233,22 @@ def connect
params[:password] = @password.value
end

Redis.new(params)
end # def connect
params
end

def params_sentinel
{
:url => @url,
:sentinels => @sentinels.map { |sentinel|
host, port = sentinel.split(":")
{
:host => host,
:port => port
}
},
:role => "master"
}
end

# A string used to identify a Redis instance in log messages
def identity
Expand Down

0 comments on commit 45ca8e5

Please sign in to comment.