Class: Redstream::Message
- Inherits:
-
Object
- Object
- Redstream::Message
- Defined in:
- lib/redstream/message.rb
Overview
The Redstream::Message class wraps a raw redis stream message to allow hash and id/offset access as well as convenient parsing of the json payload.
Instance Method Summary collapse
-
#fields ⇒ Object
As a redis stream message allows to specify fields, this allows to retrieve the fields as a hash.
-
#initialize(raw_message) ⇒ Message
constructor
private
Initializes the message.
-
#message_id ⇒ Object
Returns the message id, i.e.
-
#payload ⇒ Hash
Returns the parsed message payload as provided by the model’s #redstream_payload method.
-
#raw_message ⇒ Object
Returns the raw message content as returned by redis.
Constructor Details
#initialize(raw_message) ⇒ Message
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the message.
12 13 14 15 |
# File 'lib/redstream/message.rb', line 12 def initialize() @message_id = [0] @raw_message = end |
Instance Method Details
#fields ⇒ Object
As a redis stream message allows to specify fields, this allows to retrieve the fields as a hash.
40 41 42 |
# File 'lib/redstream/message.rb', line 40 def fields @fields ||= @raw_message[1] end |
#message_id ⇒ Object
Returns the message id, i.e. the redis message id consisting of a timestamp plus sequence number.
22 23 24 |
# File 'lib/redstream/message.rb', line 22 def @message_id end |
#payload ⇒ Hash
Returns the parsed message payload as provided by the model’s #redstream_payload method. Check out Redstream::Model for more details.
31 32 33 |
# File 'lib/redstream/message.rb', line 31 def payload @payload ||= JSON.parse(fields["payload"]) end |
#raw_message ⇒ Object
Returns the raw message content as returned by redis.
46 47 48 |
# File 'lib/redstream/message.rb', line 46 def @raw_message end |