@@ -45,6 +45,13 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base
45
45
# The Redis database number.
46
46
config :db , :validate => :number , :default => 0
47
47
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
+
48
55
# Redis initial connection timeout in seconds.
49
56
config :timeout , :validate => :number , :default => 5
50
57
@@ -200,6 +207,13 @@ def close
200
207
201
208
private
202
209
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
203
217
@current_host , @current_port = @host [ @host_idx ] . split ( ':' )
204
218
@host_idx = @host_idx + 1 >= @host . length ? 0 : @host_idx + 1
205
219
@@ -219,8 +233,22 @@ def connect
219
233
params [ :password ] = @password . value
220
234
end
221
235
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
224
252
225
253
# A string used to identify a Redis instance in log messages
226
254
def identity
0 commit comments