@@ -27,13 +27,22 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
2727 # The hostname of your Redis server.
2828 config :host , :validate => :string , :default => "127.0.0.1"
2929
30+ # The hostnames of your sentinel servers.
31+ config :sentinel_hosts , :validate => :array
32+
3033 # The port to connect on.
3134 config :port , :validate => :number , :default => 6379
3235
36+ # The sentinel port to connect on.
37+ config :sentinel_port , :validate => :number , :default => 26379
38+
39+ # The name of the sentinel master to connect to.
40+ config :sentinel_master_name , :validate => :string , :default => "mymaster"
41+
3342 # SSL
3443 config :ssl , :validate => :boolean , :default => false
3544
36- # The unix socket path to connect on. Will override host and port if defined.
45+ # The unix socket path to connect on. Will override host and port and sentinel_hosts and sentinel_port if defined.
3746 # There is no unix socket path by default.
3847 config :path , :validate => :string
3948
@@ -63,7 +72,7 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
6372 public
6473
6574 def register
66- @redis_url = @path . nil? ? "redis://#{ @password } @#{ @host } :#{ @port } /#{ @db } " : "#{ @password } @#{ @path } /#{ @db } "
75+ @redis_url = @path . nil? ? "redis://#{ @password } @#{ @sentinel_hosts . nil? ? @ host : @sentinel_master_name } :#{ @port } /#{ @db } " : "#{ @password } @#{ @path } /#{ @db } "
6776
6877 # just switch on data_type once
6978 if @data_type == 'list' || @data_type == 'dummy'
@@ -115,8 +124,18 @@ def redis_params
115124 }
116125
117126 if @path . nil?
118- params [ :host ] = @host
119- params [ :port ] = @port
127+ if @sentinel_hosts . nil?
128+ params = {
129+ :host => @host ,
130+ :port => @port
131+ }
132+ else
133+ hosts = @sentinel_hosts . map { |sentinel_host | { host : sentinel_host , port : @sentinel_port } }
134+ params = {
135+ :name => @sentinel_master_name ,
136+ :sentinels => hosts ,
137+ :role => :master
138+ }
120139 else
121140 @logger . warn ( "Parameter 'path' is set, ignoring parameters: 'host' and 'port'" )
122141 params [ :path ] = @path
0 commit comments