Class: LogStashLogger::Device::Redis
- Inherits:
-
Connectable
- Object
- Base
- Connectable
- LogStashLogger::Device::Redis
- Includes:
- Stud::Buffer
- 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
Methods inherited from Connectable
Methods inherited from Base
Constructor Details
#initialize(opts) ⇒ Redis
Returns a new instance of Redis.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/logstash-logger/device/redis.rb', line 13 def initialize(opts) super @list = opts.delete(:list) || DEFAULT_LIST normalize_path(opts) @redis_options = opts @batch_events = opts.fetch(:batch_events, 50) @batch_timeout = opts.fetch(:batch_timeout, 5) buffer_initialize max_items: @batch_events, max_interval: @batch_timeout end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
11 12 13 |
# File 'lib/logstash-logger/device/redis.rb', line 11 def list @list end |
Instance Method Details
#close ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/logstash-logger/device/redis.rb', line 52 def close buffer_flush(final: true) @io && @io.quit rescue => e warn "#{self.class} - #{e.class} - #{e.}" ensure @io = nil end |
#connect ⇒ Object
28 29 30 |
# File 'lib/logstash-logger/device/redis.rb', line 28 def connect @io = ::Redis.new(@redis_options) end |
#flush(*args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/logstash-logger/device/redis.rb', line 61 def flush(*args) if args.empty? buffer_flush else , list = *args with_connection do @io.rpush(list, ) end end end |
#reconnect ⇒ Object
32 33 34 |
# File 'lib/logstash-logger/device/redis.rb', line 32 def reconnect @io.client.reconnect end |
#with_connection ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/logstash-logger/device/redis.rb', line 36 def with_connection connect unless @io yield rescue ::Redis::InheritedError reconnect retry rescue => e warn "#{self.class} - #{e.class} - #{e.}" @io = nil end |
#write(message) ⇒ Object
47 48 49 50 |
# File 'lib/logstash-logger/device/redis.rb', line 47 def write() buffer_receive , @list buffer_flush(force: true) if @sync end |