diff --git a/lib/logstash/outputs/redis.rb b/lib/logstash/outputs/redis.rb index 3007364..78de070 100644 --- a/lib/logstash/outputs/redis.rb +++ b/lib/logstash/outputs/redis.rb @@ -58,6 +58,16 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base # TODO set required true config :key, :validate => :string, :required => false + # The value of the renamed redis RPUSH command. Note that this uses a + # non-public api in the ruby redis client and support may change in + # the future + config :rpush, :validate => :string, :required => false + + # The value of the renamed redis PUBLISH command. Note that this uses a + # non-public api in the ruby redis client and support may change in + # the future + config :publish, :validate => :string, :required => false + # Either list or channel. If `redis_type` is list, then we will set # RPUSH to key. If `redis_type` is channel, then we will PUBLISH to `key`. # TODO set required true @@ -240,7 +250,12 @@ def connect params[:password] = @password.value end - Redis.new(params) + redis = Redis.new(params) + @logger.info("Setting redis renamed commands", :rpush => @rpush, :publish => @publish) + command_map = redis.client.command_map + command_map[:rpush] = @rpush if @rpush + command_map[:publish] = @publish if @publish + redis end # def connect # A string used to identify a Redis instance in log messages diff --git a/logstash-output-redis.gemspec b/logstash-output-redis.gemspec index bf557b9..dcf766a 100644 --- a/logstash-output-redis.gemspec +++ b/logstash-output-redis.gemspec @@ -26,5 +26,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'stud' s.add_development_dependency 'logstash-devutils' + s.add_development_dependency 'logstash-codec-json' end diff --git a/spec/outputs/redis_spec.rb b/spec/outputs/redis_spec.rb index 7f4e199..8968d4a 100644 --- a/spec/outputs/redis_spec.rb +++ b/spec/outputs/redis_spec.rb @@ -3,6 +3,8 @@ require "logstash/json" require "redis" +# integration tests --------------------- + describe LogStash::Outputs::Redis, :redis => true do @@ -126,3 +128,34 @@ end end +# unit tests --------------------- + +describe LogStash::Outputs::Redis do + + let(:data_type) { 'list' } + let(:cfg) { {'key' => 'foo', 'data_type' => data_type} } + + subject do + LogStash::Plugin.lookup("output", "redis") + .new(cfg) + end + + context 'renamed redis commands' do + let(:cfg) { {'key' => 'foo', 'data_type' => data_type, 'codec' => 'json', 'rpush' => 'test rpush', 'publish' => 'test publish'} } + + before do + subject.register + end + + it 'sets the renamed commands in the command map' do + subject.on_flush_error(RuntimeError.new) # forces a connection + + command_map = subject.instance_variable_get("@redis").client.command_map + expect(command_map[:rpush]).to eq cfg['rpush'] + expect(command_map[:publish]).to eq cfg['publish'] + end + + end + +end +