Skip to content
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

Support connecting to redis sentinel. #36

Open
wants to merge 1 commit 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
32 changes: 30 additions & 2 deletions lib/logstash/outputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base
# The Redis database number.
config :db, :validate => :number, :default => 0

# Redis master URL, if using Sentinel. For example: `redis://redis-cluster`.
config :url, :valiate => :string, :default => ""

# The hostname(s) of your Redis Sentinel server(s), if using Sentinel.
# Values are formatted like the `host` setting above.
config :sentinels, :validate => :array, :default => []

# Redis initial connection timeout in seconds.
config :timeout, :validate => :number, :default => 5

Expand Down Expand Up @@ -200,6 +207,13 @@ def close

private
def connect
params = if @sentinels.size then params_sentinel else params_redis end
@logger.debug(params)

Redis.new(params)
end

def params_redis
@current_host, @current_port = @host[@host_idx].split(':')
@host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1

Expand All @@ -219,8 +233,22 @@ def connect
params[:password] = @password.value
end

Redis.new(params)
end # def connect
params
end

def params_sentinel
{
:url => @url,
:sentinels => @sentinels.map { |sentinel|
host, port = sentinel.split(":")
{
:host => host,
:port => port
}
},
:role => "master"
}
end

# A string used to identify a Redis instance in log messages
def identity
Expand Down