From 82e3dee9838461aa1ca49940b9a4a01286a30fb2 Mon Sep 17 00:00:00 2001 From: Juntao Zhang Date: Wed, 7 Sep 2016 14:54:48 +0800 Subject: [PATCH 1/2] Redis supports failover through Sentinel --- lib/logstash/outputs/redis.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/logstash/outputs/redis.rb b/lib/logstash/outputs/redis.rb index daeb5bd..2ea1342 100644 --- a/lib/logstash/outputs/redis.rb +++ b/lib/logstash/outputs/redis.rb @@ -95,6 +95,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 + + config :master, :validate => :string, :default => "mymaster" + def register require 'redis' @@ -208,8 +212,6 @@ def connect end params = { - :host => @current_host, - :port => @current_port, :timeout => @timeout, :db => @db } @@ -219,11 +221,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}" + end @name || "redis://#{@password}@#{@current_host}:#{@current_port}/#{@db} #{@data_type}:#{@key}" end From 93c03dcd2fd2700729a651297e87dc1cfb57b7e8 Mon Sep 17 00:00:00 2001 From: Juntao Zhang Date: Wed, 7 Sep 2016 15:30:06 +0800 Subject: [PATCH 2/2] redis sentinel conf example --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce56241..5d90dc4 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. \ No newline at end of file +For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file. +