Class: LogStashLogger::Device::Redis
Constant Summary
collapse
- DEFAULT_LIST =
'logstash'
Instance Attribute Summary collapse
Attributes inherited from Connectable
#buffer_logger
Attributes inherited from Base
#error_logger, #io, #sync
Instance Method Summary
collapse
Methods inherited from Connectable
#close, #connected?, #flush, #on_full_buffer_receive, #reset, #to_io, #write
Methods included from Buffer
#buffer_flush, #buffer_full?, #buffer_initialize, #buffer_receive, #reset_buffer
Methods inherited from Base
#close, #flush, #reset, #to_io, #unrecoverable_error?, #write
Constructor Details
#initialize(opts) ⇒ Redis
Returns a new instance of Redis.
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/logstash-logger/device/redis.rb', line 10
def initialize(opts)
super
@list = opts.delete(:list) || DEFAULT_LIST
@buffer_group = @list
normalize_path(opts)
delete_unknown_keywords(opts)
@redis_options = opts
end
|
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
8
9
10
|
# File 'lib/logstash-logger/device/redis.rb', line 8
def list
@list
end
|
Instance Method Details
#close! ⇒ Object
54
55
56
|
# File 'lib/logstash-logger/device/redis.rb', line 54
def close!
@io && @io.quit
end
|
#connect ⇒ Object
21
22
23
|
# File 'lib/logstash-logger/device/redis.rb', line 21
def connect
@io = ::Redis.new(@redis_options)
end
|
#reconnect ⇒ Object
25
26
27
28
29
|
# File 'lib/logstash-logger/device/redis.rb', line 25
def reconnect
@io.client.reconnect
rescue => e
log_error(e)
end
|
#with_connection ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/logstash-logger/device/redis.rb', line 31
def with_connection
connect unless connected?
yield
rescue ::Redis::InheritedError
reconnect
retry
rescue => e
log_error(e)
close(flush: false)
raise
end
|
#write_batch(messages, list = nil) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/logstash-logger/device/redis.rb', line 43
def write_batch(messages, list = nil)
list ||= @list
with_connection do
@io.rpush(list, messages)
end
end
|
#write_one(message, list = nil) ⇒ Object
50
51
52
|
# File 'lib/logstash-logger/device/redis.rb', line 50
def write_one(message, list = nil)
write_batch(message, list)
end
|