Skip to content

Commit 2a4544c

Browse files
authored
Merge pull request #1309 from willbryant/xadd_minid
Support the MINID option for XADD
2 parents 55725a2 + 4eb23d7 commit 2a4544c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/redis/commands/streams.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,25 @@ def xinfo(subcommand, key, group = nil)
4141
# @param opts [Hash] several options for `XADD` command
4242
#
4343
# @option opts [String] :id the entry id, default value is `*`, it means auto generation
44-
# @option opts [Integer] :maxlen max length of entries
45-
# @option opts [Boolean] :approximate whether to add `~` modifier of maxlen or not
44+
# @option opts [Integer] :maxlen max length of entries to keep
45+
# @option opts [Integer] :minid min id of entries to keep
46+
# @option opts [Boolean] :approximate whether to add `~` modifier of maxlen/minid or not
4647
# @option opts [Boolean] :nomkstream whether to add NOMKSTREAM, default is not to add
4748
#
4849
# @return [String] the entry id
49-
def xadd(key, entry, approximate: nil, maxlen: nil, nomkstream: nil, id: '*')
50+
def xadd(key, entry, approximate: nil, maxlen: nil, minid: nil, nomkstream: nil, id: '*')
5051
args = [:xadd, key]
5152
args << 'NOMKSTREAM' if nomkstream
5253
if maxlen
54+
raise ArgumentError, "can't supply both maxlen and minid" if minid
55+
5356
args << "MAXLEN"
5457
args << "~" if approximate
5558
args << maxlen
59+
elsif minid
60+
args << "MINID"
61+
args << "~" if approximate
62+
args << minid
5663
end
5764
args << id
5865
args.concat(entry.flatten)

test/lint/streams.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ def test_xadd_with_maxlen_and_approximate_option
8989
assert_match ENTRY_ID_FORMAT, actual
9090
end
9191

92+
def test_xadd_with_minid_and_approximate_option
93+
omit_version('6.2.0')
94+
actual = redis.xadd('s1', { f1: 'v1', f2: 'v2' }, minid: '0-1', approximate: true)
95+
assert_match ENTRY_ID_FORMAT, actual
96+
end
97+
98+
def test_xadd_with_both_maxlen_and_minid
99+
assert_raises(ArgumentError) { redis.xadd('s1', { f1: 'v1', f2: 'v2' }, maxlen: 2, minid: '0-1', approximate: true) }
100+
end
101+
92102
def test_xadd_with_nomkstream_option
93103
omit_version('6.2.0')
94104

0 commit comments

Comments
 (0)