Skip to content

Commit cdb0217

Browse files
committed
Merge branch 'release/0.3.0'
2 parents 0c32128 + 0933b46 commit cdb0217

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.0
2+
- Support for GET, SET, EXISTS, DEL, SADD, SMEMBERS and SCARD
3+
- Introduce new control field `cmd_key_is_formatted` for declaring commands
4+
to be resolved through - see %{foo} handling
5+
16
## 0.2.0
27
- Support for HSET and HGET
38

lib/logstash/filters/cache_redis.rb

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class LogStash::Filters::CacheRedis < LogStash::Filters::Base
1717

1818
config :field, :validate => :string
1919

20+
# For now only working for rpushnx and llen!
21+
config :cmd_key_is_formatted, :validate => :boolean, :default => false
22+
2023
# The hostname(s) of your Redis server(s). Ports may be specified on any
2124
# hostname, which will override the global port config.
2225
# If the hosts list is an array, Logstash will pick one random host to connect to,
@@ -47,6 +50,14 @@ class LogStash::Filters::CacheRedis < LogStash::Filters::Base
4750
# Interval for reconnecting to failed Redis connections
4851
config :reconnect_interval, :validate => :number, :default => 1
4952

53+
config :get, :validate => :string
54+
55+
config :set, :validate => :string
56+
57+
config :exists, :validate => :string
58+
59+
config :del, :validate => :string
60+
5061
# # Sets the action. If set to true, it will get the data from redis cache
5162
# config :get, :validate => :boolean, :default => false
5263
config :llen, :validate => :string
@@ -65,6 +76,12 @@ class LogStash::Filters::CacheRedis < LogStash::Filters::Base
6576
# Sets the action. If set to true, it will get the data from redis cache
6677
config :hget, :validate => :string
6778

79+
config :sadd, :validate => :string
80+
81+
config :smembers, :validate => :string
82+
83+
config :scard, :validate => :string
84+
6885
# config :get, :validate => :boolean, :default => false
6986
config :lock_timeout, :validate => :number, :default => 5000
7087

@@ -104,6 +121,22 @@ def filter(event)
104121
begin
105122
@redis ||= connect
106123

124+
if @get
125+
event.set(@target, @redis.get(event.get(@get)))
126+
end
127+
128+
if @set
129+
@redis.set(event.get(@set), event.get(@source))
130+
end
131+
132+
if @exists
133+
@redis.exists(event.get(@exists))
134+
end
135+
136+
if @del
137+
@redis.del(event.get(@del))
138+
end
139+
107140
if @hget
108141
event.set(@target, @redis.hget(event.get(@hget), event.get(@source)))
109142
end
@@ -112,16 +145,29 @@ def filter(event)
112145
@redis.hset(event.get(@hset), event.get(@field), event.get(@source))
113146
end
114147

148+
if @sadd
149+
@redis.sadd(event.get(@sadd), event.get(@source))
150+
end
151+
152+
if @smembers
153+
@redis.smembers(event.get(@smembers))
154+
end
155+
156+
if @scard
157+
event.set(@target, @redis.scard(event.get(@scard)))
158+
end
159+
115160
if @llen
116-
event.set(@target, @redis.llen(event.get(@llen)))
161+
key = @cmd_key_is_formatted ? event.sprintf(@llen) : event.get(@llen)
162+
event.set(@target, @redis.llen(key))
117163
end
118164

119165
if @rpush
120166
@redis.rpush(event.get(@rpush), event.get(@source))
121167
end
122168

123169
if @rpushnx
124-
key = event.get(@rpushnx)
170+
key = @cmd_key_is_formatted ? event.sprintf(@rpushnx) : event.get(@rpushnx)
125171
begin
126172
@lock_manager ||= connect_lockmanager
127173
@lock_manager.lock!("lock_#{key}", @lock_timeout) do

logstash-filter-cache-redis.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-filter-cache-redis'
3-
s.version = '0.2.0'
3+
s.version = '0.3.0'
44
s.licenses = ['MIT']
55
s.summary = "Redis Cache Filter for Logstash"
66
s.description = "A Logstash filter plugin for storing and retrieving data from redis cache. This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gem_name. This gem is not a stand-alone program."

0 commit comments

Comments
 (0)