diff --git a/lib/logstash/outputs/redis.rb b/lib/logstash/outputs/redis.rb index 81e3c9b..3e9feb5 100644 --- a/lib/logstash/outputs/redis.rb +++ b/lib/logstash/outputs/redis.rb @@ -31,7 +31,7 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base # For example: # [source,ruby] # "127.0.0.1" - # ["127.0.0.1", "127.0.0.2"] + # ["127.0.0.1", "127.0.0.2", "/var/run/redis/redis.sock"] # ["127.0.0.1:6380", "127.0.0.1"] config :host, :validate => :array, :default => ["127.0.0.1"] @@ -178,31 +178,44 @@ def close private def connect - @current_host, @current_port = @host[@host_idx].split(':') - @host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1 + if @host[@host_idx].start_with?("/") + @current_path = @host[@host_idx] + connectionParams = { + :path => @current_path + } + else + @current_host, @current_port = @host[@host_idx].split(':') + + if not @current_port + @current_port = @port + end - if not @current_port - @current_port = @port + connectionParams = { + :host => @current_host, + :port => @current_port + } end - - params = { - :host => @current_host, - :port => @current_port, + + baseParams = { :timeout => @timeout, - :db => @db + :db => @db, + :password => @password.nil? ? nil : @password.value } - @logger.debug("connection params", params) - if @password - params[:password] = @password.value - end + params = connectionParams.merge(baseParams) + @logger.debug("connection params", params) + + @host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1 + Redis.new(params) + end # def connect # A string used to identify a Redis instance in log messages def identity - "redis://#{@password}@#{@current_host}:#{@current_port}/#{@db} #{@data_type}:#{@key}" + @redis_url = @current_path.nil? ? "redis://#{@password}@#{@current_host}:#{@current_port}/#{@db}" : "#{@password}@#{@pcurrent_path}/#{@db}" + return "#{@redis_url} #{@data_type}:#{@key}" end def send_to_redis(event, payload)