Method: Cosmos::Store#write_topic

Defined in:
lib/cosmos/utilities/store_autoload.rb

#write_topic(topic, msg_hash, id = '*', maxlen = nil, approximate = true) ⇒ String

Add new entry to the redis stream. > www.rubydoc.info/github/redis/redis-rb/Redis:xadd

Examples:

Without options

store.write_topic('MANGO__TOPIC', {'message' => 'something'})

With options

store.write_topic('MANGO__TOPIC', {'message' => 'something'}, id: '0-0', maxlen: 1000, approximate: true)

Parameters:

  • topic (String)

    the stream / topic

  • msg_hash (Hash)

    one or multiple field-value pairs

  • opts (Hash)

    a customizable set of options

Returns:



194
195
196
197
198
199
200
# File 'lib/cosmos/utilities/store_autoload.rb', line 194

def write_topic(topic, msg_hash, id = '*', maxlen = nil, approximate = true)
  id = '*' if id.nil?
  # Logger.debug "write_topic topic:#{topic} id:#{id} hash:#{msg_hash}"
  @redis_pool.with do |redis|
    return redis.xadd(topic, msg_hash, id: id, maxlen: maxlen, approximate: approximate)
  end
end