Class: Redstream::Message

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • raw_message (Array)

    The raw message as returned by redis



12
13
14
15
# File 'lib/redstream/message.rb', line 12

def initialize(raw_message)
  @message_id = raw_message[0]
  @raw_message = raw_message
end

Instance Method Details

#fieldsObject

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_idObject

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
  @message_id
end

#payloadHash

Returns the parsed message payload as provided by the model’s #redstream_payload method. Check out Redstream::Model for more details.

Returns:

  • (Hash)

    The parsed payload



31
32
33
# File 'lib/redstream/message.rb', line 31

def payload
  @payload ||= JSON.parse(fields["payload"])
end

#raw_messageObject

Returns the raw message content as returned by redis.



46
47
48
# File 'lib/redstream/message.rb', line 46

def raw_message
  @raw_message
end