module Redis::Commands::Streams
def xadd(key, entry, approximate: nil, maxlen: nil, minid: nil, nomkstream: nil, id: '*')
-
(String)
- the entry id
Options Hash:
(**opts)
-
:nomkstream
(Boolean
) -- whether to add NOMKSTREAM, default is not to add -
:approximate
(Boolean
) -- whether to add `~` modifier of maxlen/minid or not -
:minid
(Integer
) -- min id of entries to keep -
:maxlen
(Integer
) -- max length of entries to keep -
:id
(String
) -- the entry id, default value is `*`, it means auto generation
Parameters:
-
opts
(Hash
) -- several options for `XADD` command -
entry
(Hash
) -- one or multiple field-value pairs -
key
(String
) -- the stream key
Other tags:
- Example: With options -
Example: Without options -
def xadd(key, entry, approximate: nil, maxlen: nil, minid: nil, nomkstream: nil, id: '*') args = [:xadd, key] args << 'NOMKSTREAM' if nomkstream if maxlen raise ArgumentError, "can't supply both maxlen and minid" if minid args << "MAXLEN" args << "~" if approximate args << maxlen elsif minid args << "MINID" args << "~" if approximate args << minid end args << id args.concat(entry.flatten) send_command(args) end