Skip to content

Commit 37d2051

Browse files
committed
add cluster support
1 parent 2b0e5b7 commit 37d2051

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

lib/logstash/inputs/redis.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
3030
# The hostnames of your sentinel servers.
3131
config :sentinel_hosts, :validate => :array
3232

33+
# The connection URLs of your cluster servers.
34+
config :cluster_hosts, :validate => :array
35+
3336
# The port to connect on.
3437
config :port, :validate => :number, :default => 6379
3538

@@ -42,7 +45,7 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
4245
# SSL
4346
config :ssl, :validate => :boolean, :default => false
4447

45-
# The unix socket path to connect on. Will override host and port and sentinel_hosts and sentinel_port if defined.
48+
# The unix socket path to connect on. Will override host and port and sentinel_hosts and sentinel_port and cluster_hosts if defined.
4649
# There is no unix socket path by default.
4750
config :path, :validate => :string
4851

@@ -72,7 +75,15 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
7275
public
7376

7477
def register
75-
@redis_url = @path.nil? ? "redis://#{@password}@#{@sentinel_hosts.nil? ? @host : @sentinel_master_name}:#{@port}/#{@db}" : "#{@password}@#{@path}/#{@db}"
78+
if !@path.nil?
79+
@redis_url = "#{@password}@#{@path}/#{@db}"
80+
if !@cluster_hosts.nil?
81+
@redis_url = "#{@password}@#{@cluster_hosts.map { |h| "#{h}" }.join(',')}/#{@db}"
82+
elsif !@sentinel_hosts.nil?
83+
@redis_url = "redis://#{@password}@#{@sentinel_master_name}:#{@port}/#{@db}"
84+
else
85+
@redis_url = "redis://#{@password}@#{@host}:#{@port}/#{@db}"
86+
end
7687

7788
# just switch on data_type once
7889
if @data_type == 'list' || @data_type == 'dummy'
@@ -124,18 +135,22 @@ def redis_params
124135
}
125136

126137
if @path.nil?
127-
if @sentinel_hosts.nil?
138+
if !@cluster_hosts.nil?
128139
params = {
129-
:host => @host,
130-
:port => @port
140+
:cluster => cluster_hosts,
131141
}
132-
else
142+
elsif !@sentinel_hosts.nil?
133143
hosts = @sentinel_hosts.map { |sentinel_host| { host: sentinel_host, port: @sentinel_port } }
134144
params = {
135145
:name => @sentinel_master_name,
136146
:sentinels => hosts,
137147
:role => :master
138148
}
149+
else
150+
params = {
151+
:host => @host,
152+
:port => @port
153+
}
139154
else
140155
@logger.warn("Parameter 'path' is set, ignoring parameters: 'host' and 'port'")
141156
params[:path] = @path

0 commit comments

Comments
 (0)