Skip to content

Adding support for renamed redis rpush and publish commands. #17

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 1 commit 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 lib/logstash/outputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions logstash-output-redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

33 changes: 33 additions & 0 deletions spec/outputs/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "logstash/json"
require "redis"

# integration tests ---------------------

describe LogStash::Outputs::Redis, :redis => true do


Expand Down Expand Up @@ -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