Class: LogStashLogger::Device::Redis
- Inherits:
-
Connectable
- Object
- Base
- Connectable
- LogStashLogger::Device::Redis
- Defined in:
- lib/logstash-logger/device/redis.rb
Constant Summary collapse
- DEFAULT_LIST =
'logstash'
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Attributes inherited from Base
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #flush(*args) ⇒ Object
-
#initialize(opts) ⇒ Redis
constructor
A new instance of Redis.
- #reconnect ⇒ Object
- #with_connection ⇒ Object
- #write(message) ⇒ Object
- #write_batch(messages, list = nil) ⇒ Object
Methods inherited from Connectable
Methods inherited from Base
Constructor Details
#initialize(opts) ⇒ Redis
Returns a new instance of Redis.
10 11 12 13 14 15 16 17 |
# File 'lib/logstash-logger/device/redis.rb', line 10 def initialize(opts) super @list = opts.delete(:list) || DEFAULT_LIST normalize_path(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
50 51 52 53 54 55 56 57 |
# File 'lib/logstash-logger/device/redis.rb', line 50 def close buffer_flush(final: true) @io && @io.quit rescue => e warn "#{self.class} - #{e.class} - #{e.}" ensure @io = nil end |
#connect ⇒ Object
19 20 21 |
# File 'lib/logstash-logger/device/redis.rb', line 19 def connect @io = ::Redis.new(@redis_options) end |
#flush(*args) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/logstash-logger/device/redis.rb', line 59 def flush(*args) if args.empty? buffer_flush else , list = *args write_batch(, list) end end |
#reconnect ⇒ Object
23 24 25 |
# File 'lib/logstash-logger/device/redis.rb', line 23 def reconnect @io.client.reconnect end |
#with_connection ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/logstash-logger/device/redis.rb', line 27 def with_connection connect unless @io yield rescue ::Redis::InheritedError reconnect retry rescue => e warn "#{self.class} - #{e.class} - #{e.}" @io = nil raise end |
#write(message) ⇒ Object
39 40 41 42 |
# File 'lib/logstash-logger/device/redis.rb', line 39 def write() buffer_receive , @list buffer_flush(force: true) if @sync end |
#write_batch(messages, list = nil) ⇒ Object
44 45 46 47 48 |
# File 'lib/logstash-logger/device/redis.rb', line 44 def write_batch(, list = nil) with_connection do @io.rpush(list, ) end end |