diff --git a/lib/redis/commands/streams.rb b/lib/redis/commands/streams.rb index e3c75068..580af68a 100644 --- a/lib/redis/commands/streams.rb +++ b/lib/redis/commands/streams.rb @@ -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) diff --git a/test/lint/streams.rb b/test/lint/streams.rb index f23a4ae8..8f7b771d 100644 --- a/test/lint/streams.rb +++ b/test/lint/streams.rb @@ -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')