Skip to content

Redis supports failover through Sentinel #39

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 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#Changelog

#####redis-sentinel example conf

```
redis {
data_type=>"list"
db=>0
key=>"logstash-%{type}"
sentinel_hosts=>["127.0.0.1:26380"]
password=>"123"
}
```

# Logstash Plugin

[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-output-redis.svg)](https://travis-ci.org/logstash-plugins/logstash-output-redis)
Expand Down Expand Up @@ -95,4 +109,5 @@ Programming is not a required skill. Whatever you've seen about open source and

It is more important to the community that you are able to contribute.

For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.

28 changes: 26 additions & 2 deletions lib/logstash/outputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base
# Zero means to check on every event.
config :congestion_interval, :validate => :number, :default => 1

config :sentinel_hosts, :validate => :array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide documentation for these settings in the docs/index.asciidoc file?


config :master, :validate => :string, :default => "mymaster"

def register
require 'redis'

Expand Down Expand Up @@ -186,8 +190,6 @@ def connect
end

params = {
:host => @current_host,
:port => @current_port,
:timeout => @timeout,
:db => @db
}
Expand All @@ -197,11 +199,33 @@ def connect
params[:password] = @password.value
end

if @sentinel_hosts
@logger.info('Connecting to sentinel')
hosts = []
for sentinel_host in @sentinel_hosts
host, port = sentinel_host.split(":")
unless port
port = @sentinel_port
end
hosts.push({:host => host, :port => port})
end
params[:url] = 'redis://'+@master
params[:sentinels] = hosts
params[:role] = :master
else
params[:host] = @current_host
params[:port] = @current_port
end


Redis.new(params)
end # def connect

# A string used to identify a Redis instance in log messages
def identity
if @sentinel_hosts
return "redis-sentinel://#{@password} #{$sentinel_hosts} #{@db} #{@data_type}:#{@key}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be @sentinel_hosts instead?

end
"redis://#{@password}@#{@current_host}:#{@current_port}/#{@db} #{@data_type}:#{@key}"
end

Expand Down