diff --git a/lib/logstash/inputs/couchdb_changes.rb b/lib/logstash/inputs/couchdb_changes.rb index 3a7cc12..f63c71d 100644 --- a/lib/logstash/inputs/couchdb_changes.rb +++ b/lib/logstash/inputs/couchdb_changes.rb @@ -132,16 +132,29 @@ def register module SequenceDB class File def initialize(file) - @sequence_path = file + @uri = URI.parse(file) + if @uri.scheme == "redis" + @entry = @uri.path.split(File::SEPARATOR)[-1] + @uri.path = @uri.path.split(File::SEPARATOR)[0...-1].join(File::Separator) + @client = Redis.new(url: @uri) + end end def read - ::File.exists?(@sequence_path) ? ::File.read(@sequence_path).chomp.strip : 0 + if @uri.scheme.nil? + ::File.exists?(@sequence_path) ? ::File.read(@sequence_path).chomp.strip : 0 + elsif @uri.scheme == "redis" + @client.get(@entry) + end end def write(sequence = nil) sequence = 0 if sequence.nil? - ::File.write(@sequence_path, sequence.to_s) + if @uri.scheme.nil? + ::File.write(@sequence_path, sequence.to_s) + elsif @uri.scheme == "redis" + @client.set(@entry, sequence) + end end end end diff --git a/logstash-input-couchdb_changes.gemspec b/logstash-input-couchdb_changes.gemspec index c684464..393872b 100644 --- a/logstash-input-couchdb_changes.gemspec +++ b/logstash-input-couchdb_changes.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency "stud", '>= 0.0.22' s.add_runtime_dependency 'logstash-codec-plain' s.add_runtime_dependency 'json' + s.add_runtime_dependency 'redis' s.add_development_dependency 'ftw', '~> 0.0.42' s.add_development_dependency 'logstash-devutils'