Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/redis/commands/streams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,25 @@ def xinfo(subcommand, key, group = nil)
# @param opts [Hash] several options for `XADD` command
#
# @option opts [String] :id the entry id, default value is `*`, it means auto generation
# @option opts [Integer] :maxlen max length of entries
# @option opts [Boolean] :approximate whether to add `~` modifier of maxlen or not
# @option opts [Integer] :maxlen max length of entries to keep
# @option opts [Integer] :minid min id of entries to keep
# @option opts [Boolean] :approximate whether to add `~` modifier of maxlen/minid or not
# @option opts [Boolean] :nomkstream whether to add NOMKSTREAM, default is not to add
#
# @return [String] the entry id
def xadd(key, entry, approximate: nil, maxlen: nil, nomkstream: nil, id: '*')
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)
Expand Down
10 changes: 10 additions & 0 deletions test/lint/streams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ def test_xadd_with_maxlen_and_approximate_option
assert_match ENTRY_ID_FORMAT, actual
end

def test_xadd_with_minid_and_approximate_option
omit_version('6.2.0')
actual = redis.xadd('s1', { f1: 'v1', f2: 'v2' }, minid: '0-1', approximate: true)
assert_match ENTRY_ID_FORMAT, actual
end

def test_xadd_with_both_maxlen_and_minid
assert_raises(ArgumentError) { redis.xadd('s1', { f1: 'v1', f2: 'v2' }, maxlen: 2, minid: '0-1', approximate: true) }
end

def test_xadd_with_nomkstream_option
omit_version('6.2.0')

Expand Down
Loading