Skip to content

Commit 9f09af5

Browse files
committed
Support connecting to redis sentinel.
* Expose `url` and `sentinels` options. * Connect to sentinel if options are passed.
1 parent 5e36d24 commit 9f09af5

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

lib/logstash/outputs/redis.rb

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base
4545
# The Redis database number.
4646
config :db, :validate => :number, :default => 0
4747

48+
# Redis master URL, if using Sentinel. For example: `redis://redis-cluster`.
49+
config :url, :valiate => :string, :default => ""
50+
51+
# The hostname(s) of your Redis Sentinel server(s), if using Sentinel.
52+
# Values are formatted like the `host` setting above.
53+
config :sentinels, :validate => :array, :default => []
54+
4855
# Redis initial connection timeout in seconds.
4956
config :timeout, :validate => :number, :default => 5
5057

@@ -200,6 +207,13 @@ def close
200207

201208
private
202209
def connect
210+
params = if @sentinels.size then params_sentinel else params_redis end
211+
@logger.debug(params)
212+
213+
Redis.new(params)
214+
end
215+
216+
def params_redis
203217
@current_host, @current_port = @host[@host_idx].split(':')
204218
@host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1
205219

@@ -219,8 +233,22 @@ def connect
219233
params[:password] = @password.value
220234
end
221235

222-
Redis.new(params)
223-
end # def connect
236+
params
237+
end
238+
239+
def params_sentinel
240+
{
241+
:url => @url,
242+
:sentinels => @sentinels.map { |sentinel|
243+
host, port = sentinel.split(":")
244+
{
245+
:host => host,
246+
:port => port
247+
}
248+
},
249+
:role => "master"
250+
}
251+
end
224252

225253
# A string used to identify a Redis instance in log messages
226254
def identity

0 commit comments

Comments
 (0)