Class: LogstashRails::Transport::Redis

Inherits:
LogstashRails::TransportBase show all
Defined in:
lib/logstash_rails/transport/redis.rb

Instance Method Summary collapse

Methods inherited from LogstashRails::TransportBase

#destroy

Constructor Details

#initialize(formatter, options) ⇒ Redis

Returns a new instance of Redis.

Parameters:

  • options (Hash)

    configuration options

Options Hash (options):

  • :host (Symbol) — default: '127.0.0.1'

    the host with the redis server

  • :port (Symbol) — default: 6379

    the port to connect to

  • :redis_key (Symbol) — default: 'logstash'

    the key of the redis list to which events will be pushed to



13
14
15
16
17
18
19
20
21
22
# File 'lib/logstash_rails/transport/redis.rb', line 13

def initialize(formatter, options)
  host = options[:host] || '127.0.0.1'
  port = options[:port] || 6379
  redis_key = options[:redis_key] || 'logstash'

  @redis = ::Redis.new(host: host, port: port)
  @redis_key = redis_key

  super
end

Instance Method Details

#push(json_event) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/logstash_rails/transport/redis.rb', line 24

def push(json_event)
  begin
    unless @redis.rpush(@redis_key, json_event)
      raise "could not send event to redis"
    end
  rescue ::Redis::InheritedError
    @redis.client.connect
    retry
  end
end