Class: RedisLogstash::Socket
- Inherits:
-
Object
- Object
- RedisLogstash::Socket
- Defined in:
- lib/redis_logstash/socket.rb
Constant Summary collapse
- @@socket =
nil
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#redis_key ⇒ Object
Returns the value of attribute redis_key.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Socket
constructor
A new instance of Socket.
- #push(json) ⇒ Object
Constructor Details
#initialize ⇒ Socket
Returns a new instance of Socket.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/redis_logstash/socket.rb', line 19 def initialize self. = ParseConfig.get[:redis] host = [:host] || '127.0.0.1' port = [:port] || 6379 password = [:password] || nil self.redis_key = [:key] || 'logstash' self.redis = password ? ::Redis.new(host: host, port: port, password: password) : ::Redis.new(host: host, port: port) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/redis_logstash/socket.rb', line 6 def @options end |
#redis ⇒ Object
Returns the value of attribute redis.
6 7 8 |
# File 'lib/redis_logstash/socket.rb', line 6 def redis @redis end |
#redis_key ⇒ Object
Returns the value of attribute redis_key.
6 7 8 |
# File 'lib/redis_logstash/socket.rb', line 6 def redis_key @redis_key end |
Class Method Details
.get ⇒ Object
9 10 11 |
# File 'lib/redis_logstash/socket.rb', line 9 def get @@socket ||= new end |
.write(json) ⇒ Object
13 14 15 |
# File 'lib/redis_logstash/socket.rb', line 13 def write(json) get.push(json) end |
Instance Method Details
#push(json) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/redis_logstash/socket.rb', line 31 def push(json) begin unless redis.rpush(redis_key, Logger.gzip({type: [:type], logs: json.to_json}.to_json)) raise "could not send event to redis" end rescue ::Redis::InheritedError redis.client.connect retry end end |