class Fluent::RedisStoreOutput
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 34 def initialize super require 'redis' require 'msgpack' require 'cgi' end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 41 def configure(conf) super if @key_path == nil and @key == nil raise Fluent::ConfigError, "either key_path or key is required" end end
escape_html(string)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 207 def escape_html(string) string = CGI::escapeHTML(string) return string end
filter_html_tag(string)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 212 def filter_html_tag(string) string = string.gsub("&","") string = string.gsub("<","") string = string.gsub(">","") string = string.gsub("'","") string = string.gsub("\"","") return string end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 64 def format(tag, time, record) [tag, time, record].to_msgpack end
get_key_from(record)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 233 def get_key_from(record) if @key k = @key else k = traverse(record, @key_path).to_s end key = @key_prefix + k + @key_suffix raise Fluent::ConfigError, "key is empty" if key == '' key end
get_score_from(record, time)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 257 def get_score_from(record, time) if @score_path traverse(record, @score_path) else time end end
get_value_from(record)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 245 def get_value_from(record) value = traverse(record, @value_path) case @format_type when 'json' value.to_json when 'msgpack' value.to_msgpack else value end end
lower_string(string)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 198 def lower_string(string) return string.downcase end
operation_for_list(record)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 145 def operation_for_list(record) key = get_key_from(record) value = get_value_from(record) if 0 < @string_tolow value = lower_string(value) end if 0 < @string_unescape value = unescape_string(value) if 0 <@string_unescape_twice value = unescape_string(value) end end if 0 < @string_escape_html value = escape_html(value) end if 0 < @filter_html value = filter_html_tag(value) end if 0 < @only_alphanumeric if ( /^[a-zA-Z0-9 ]*$/.match(value) ) != nil else return end end if 0 < @prevent_duplicate @redis.lrem key.to_s, 1, value.to_s end if @order == 'asc' @redis.rpush key, value else @redis.lpush key, value end set_key_expire key if 0 < @value_length @redis.ltrim key, 0, @value_length - 1 end end
operation_for_publish(record)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 192 def operation_for_publish(record) key = get_key_from(record) value = get_value_from(record) @redis.publish key, value end
operation_for_set(record)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 138 def operation_for_set(record) key = get_key_from(record) value = get_value_from(record) @redis.sadd key, value set_key_expire key end
operation_for_string(record)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 184 def operation_for_string(record) key = get_key_from(record) value = get_value_from(record) @redis.set key, value set_key_expire key end
operation_for_zset(record, time)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 98 def operation_for_zset(record, time) key = get_key_from(record) value = get_value_from(record) score = get_score_from(record, time) if 0 < @string_tolow value = lower_string(value) end if 0 < @string_unescape value = unescape_string(value) if 0 <@string_unescape_twice value = unescape_string(value) end end if 0 < @string_escape_html value = escape_html(value) end if 0 < @filter_html value = filter_html_tag(value) end if 0 < @only_alphanumeric if ( /^[a-zA-Z0-9 ]*$/.match(value) ) != nil else return end end @redis.zadd key, score, value set_key_expire key if 0 < @value_expire now = Time.now.to_i @redis.zremrangebyscore key , '-inf' , (now - @value_expire) end if 0 < @value_length l = -1 - @value_length @redis.zremrangebyrank key, 0, l end end
set_key_expire(key)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 265 def set_key_expire(key) if 0 < @key_expire @redis.expire key, @key_expire end end
shutdown()
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 60 def shutdown @redis.quit end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 49 def start super if @path @redis = Redis.new(:path => @path, :password => @password, :timeout => @timeout, :thread_safe => true, :db => @db) else @redis = Redis.new(:host => @host, :port => @port, :password => @password, :timeout => @timeout, :thread_safe => true, :db => @db) end end
traverse(data, key)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 221 def traverse(data, key) val = data key.split('.').each{ |k| if val.has_key?(k) val = val[k] else return nil end } return val end
unescape_string(string)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 202 def unescape_string(string) string = CGI.unescape(string) return string end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_redis_store_wejick.rb, line 68 def write(chunk) @redis.pipelined { chunk.open { |io| begin MessagePack::Unpacker.new(io).each { |message| begin (tag, time, record) = message case @store_type when 'zset' operation_for_zset(record, time) when 'set' operation_for_set(record) when 'list' operation_for_list(record) when 'string' operation_for_string(record) when 'publish' operation_for_publish(record) end rescue NoMethodError => e puts e end } rescue EOFError # EOFError always occured when reached end of chunk. end } } end