Skip to content

Add support for Redis unix sockets #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions lib/logstash/outputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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)
Expand Down