Module: RedisSyslog::MessageEncoder
- Defined in:
- lib/redis_syslog.rb
Class Method Summary collapse
- .decode(data) ⇒ Object
-
.encode(index:, timestamp:, message:) ⇒ Object
Encode a message with a timestamp fit for inserting into a redis set.
Class Method Details
.decode(data) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/redis_syslog.rb', line 12 def self.decode(data) info = data.split("\n") index = info.shift.to_i = info.shift.to_i #Retrieve by inverting the rest = data.gsub(self.encode(index: index, timestamp: , message:""), "") return {index: index, timestamp: , message: } end |
.encode(index:, timestamp:, message:) ⇒ Object
Encode a message with a timestamp fit for inserting into a redis set. This must include the index itself because a non-unique message could end up getting ignored by redis because it’s technically a duplicate if the timestamp happened to be the same. We’re encoding to INDEXnTIMESTAMPnMESSAGE
8 9 10 |
# File 'lib/redis_syslog.rb', line 8 def self.encode(index:, timestamp:, message:) "#{index}\n#{timestamp}\n#{message}" end |