Class: Resque::Plugins::Logstash::Transport::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/logstash/transport/redis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = nil, key = 'logstash') ⇒ Redis

Returns a new instance of Redis.



5
6
7
8
9
10
11
12
# File 'lib/resque/logstash/transport/redis.rb', line 5

def initialize(host, port = nil, key = 'logstash')
  if host.is_a?(Hash)
    initialize_with_keyword_arguments(host)
  else
    @redis_options = { host: host, port: port }
    @key = key
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



24
25
26
# File 'lib/resque/logstash/transport/redis.rb', line 24

def key
  @key
end

Instance Method Details

#hostObject



30
31
32
# File 'lib/resque/logstash/transport/redis.rb', line 30

def host
  @redis_options[:host]
end

#initialize_with_keyword_arguments(key: 'logstash', redis: nil, **redis_options) ⇒ Object



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

def initialize_with_keyword_arguments(key: 'logstash', redis: nil, **redis_options)
  @key = key

  if redis
    @redis = redis
  else
    @redis_options = redis_options
  end
end

#portObject



34
35
36
# File 'lib/resque/logstash/transport/redis.rb', line 34

def port
  @redis_options[:port]
end

#push(value) ⇒ Object



38
39
40
# File 'lib/resque/logstash/transport/redis.rb', line 38

def push(value)
  redis.rpush @key, value.to_json
end

#redisObject



26
27
28
# File 'lib/resque/logstash/transport/redis.rb', line 26

def redis
  @redis ||= ::Redis.new(@redis_options)
end