Sha256: 62e375a41c559f2008deb192a572e5d61430d95682abaef9a11f6b5e628fa1d7
Contents?: true
Size: 1.24 KB
Versions: 20
Compression:
Stored size: 1.24 KB
Contents
require 'redis' module LogStashLogger module Device class Redis < Connectable DEFAULT_LIST = 'logstash' attr_accessor :list def initialize(opts) super @list = opts.delete(:list) || DEFAULT_LIST @buffer_group = @list normalize_path(opts) @redis_options = opts end def connect @io = ::Redis.new(@redis_options) end def reconnect @io.client.reconnect rescue => e log_error(e) end def with_connection connect unless connected? yield rescue ::Redis::InheritedError reconnect retry rescue => e log_error(e) close(flush: false) raise end def write_batch(messages, list = nil) list ||= @list with_connection do @io.rpush(list, messages) end end def write_one(message, list = nil) write_batch(message, list) end def close! @io && @io.quit end private def normalize_path(opts) path = opts.fetch(:path, nil) if path opts[:db] = path.gsub("/", "").to_i unless path.empty? opts.delete(:path) end end end end end
Version data entries
20 entries across 20 versions & 2 rubygems