Skip to content

Commit dba90d8

Browse files
karesyaauie
andauthored
Fix: resolve crash when commands_map is set (#86)
* Fix: do not rely on redis.client anymore * Test: redo specs with 'real' Redis mocking * Refactor: cleanup plugin (internals) Co-authored-by: Ry Biesemeyer <[email protected]>
1 parent 45a6702 commit dba90d8

File tree

4 files changed

+136
-183
lines changed

4 files changed

+136
-183
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.6.1
2+
- Fix: resolve crash when commands_map is set [#86](https://github.com/logstash-plugins/logstash-input-redis/pull/86)
3+
14
## 3.6.0
25
- Remove ruby pipeline dependency. Starting from Logstash 8, Ruby execution engine is not available. All pipelines should use Java pipeline [#84](https://github.com/logstash-plugins/logstash-input-redis/pull/84)
36

lib/logstash/inputs/redis.rb

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,10 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
6161
config :command_map, :validate => :hash, :default => {}
6262

6363
public
64-
# public API
65-
# use to store a proc that can provide a Redis instance or mock
66-
def add_external_redis_builder(builder) #callable
67-
@redis_builder = builder
68-
self
69-
end
70-
71-
# use to apply an instance directly and bypass the builder
72-
def use_redis(instance)
73-
@redis = instance
74-
self
75-
end
76-
77-
def new_redis_instance
78-
@redis_builder.call
79-
end
8064

8165
def register
8266
@redis_url = @path.nil? ? "redis://#{@password}@#{@host}:#{@port}/#{@db}" : "#{@password}@#{@path}/#{@db}"
8367

84-
@redis_builder ||= method(:internal_redis_builder)
85-
8668
# just switch on data_type once
8769
if @data_type == 'list' || @data_type == 'dummy'
8870
@run_method = method(:list_runner)
@@ -147,8 +129,7 @@ def redis_params
147129
return connectionParams.merge(baseParams)
148130
end
149131

150-
# private
151-
def internal_redis_builder
132+
def new_redis_instance
152133
::Redis.new(redis_params)
153134
end
154135

@@ -157,14 +138,12 @@ def connect
157138
redis = new_redis_instance
158139

159140
# register any renamed Redis commands
160-
if @command_map.any?
161-
client_command_map = redis.client.command_map
162-
@command_map.each do |name, renamed|
163-
client_command_map[name.to_sym] = renamed.to_sym
164-
end
141+
@command_map.each do |name, renamed|
142+
redis._client.command_map[name.to_sym] = renamed.to_sym
165143
end
166144

167145
load_batch_script(redis) if batched? && is_list_type?
146+
168147
redis
169148
end # def connect
170149

@@ -208,7 +187,9 @@ def list_runner(output_queue)
208187
@redis ||= connect
209188
@list_method.call(@redis, output_queue)
210189
rescue ::Redis::BaseError => e
211-
@logger.warn("Redis connection problem", :exception => e)
190+
info = { message: e.message, exception: e.class }
191+
info[:backtrace] = e.backtrace if @logger.debug?
192+
@logger.warn("Redis connection problem", info)
212193
# Reset the redis variable to trigger reconnect
213194
@redis = nil
214195
# this sleep does not need to be stoppable as its
@@ -270,14 +251,14 @@ def subscribe_stop
270251
return if @redis.nil? || !@redis.connected?
271252
# if its a SubscribedClient then:
272253
# it does not have a disconnect method (yet)
273-
if @redis.client.is_a?(::Redis::SubscribedClient)
254+
if @redis.subscribed?
274255
if @data_type == 'pattern_channel'
275-
@redis.client.punsubscribe
256+
@redis.punsubscribe
276257
else
277-
@redis.client.unsubscribe
258+
@redis.unsubscribe
278259
end
279260
else
280-
@redis.client.disconnect
261+
@redis.disconnect!
281262
end
282263
@redis = nil
283264
end

logstash-input-redis.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-input-redis'
4-
s.version = '3.6.0'
4+
s.version = '3.6.1'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Reads events from a Redis instance"
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
2323
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
2424

2525
s.add_runtime_dependency 'logstash-codec-json'
26-
s.add_runtime_dependency 'redis', '~> 4'
26+
s.add_runtime_dependency 'redis', '>= 4.0.1', '< 5'
2727

2828
s.add_development_dependency 'logstash-devutils'
2929
end

0 commit comments

Comments
 (0)