Skip to content

Commit 2c0f0db

Browse files
Add NOMKSTREAM option to XADD
1 parent fe90f6d commit 2c0f0db

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/redis/commands/streams.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def xinfo(subcommand, key, group = nil)
3434
# @example Without options
3535
# redis.xadd('mystream', f1: 'v1', f2: 'v2')
3636
# @example With options
37-
# redis.xadd('mystream', { f1: 'v1', f2: 'v2' }, id: '0-0', maxlen: 1000, approximate: true)
37+
# redis.xadd('mystream', { f1: 'v1', f2: 'v2' }, id: '0-0', maxlen: 1000, approximate: true, nomkstream: true)
3838
#
3939
# @param key [String] the stream key
4040
# @param entry [Hash] one or multiple field-value pairs
@@ -43,10 +43,12 @@ def xinfo(subcommand, key, group = nil)
4343
# @option opts [String] :id the entry id, default value is `*`, it means auto generation
4444
# @option opts [Integer] :maxlen max length of entries
4545
# @option opts [Boolean] :approximate whether to add `~` modifier of maxlen or not
46+
# @option opts [Boolean] :nomkstream whether to add NOMKSTREAM, default is not to add
4647
#
4748
# @return [String] the entry id
48-
def xadd(key, entry, approximate: nil, maxlen: nil, id: '*')
49+
def xadd(key, entry, approximate: nil, maxlen: nil, nomkstream: nil, id: '*')
4950
args = [:xadd, key]
51+
args << 'NOMKSTREAM' if nomkstream
5052
if maxlen
5153
args << "MAXLEN"
5254
args << "~" if approximate

test/lint/streams.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module Lint
44
module Streams
55
MIN_REDIS_VERSION = '4.9.0'
6-
MIN_REDIS_VERSION_XAUTOCLAIM = '6.2.0'
76
ENTRY_ID_FORMAT = /\d+-\d+/.freeze
87

98
def setup
@@ -90,6 +89,16 @@ def test_xadd_with_maxlen_and_approximate_option
9089
assert_match ENTRY_ID_FORMAT, actual
9190
end
9291

92+
def test_xadd_with_nomkstream_option
93+
omit_version('6.2.0')
94+
95+
actual = redis.xadd('s1', { f1: 'v1', f2: 'v2' }, nomkstream: true)
96+
assert_nil actual
97+
98+
actual = redis.xadd('s1', { f1: 'v1', f2: 'v2' }, nomkstream: false)
99+
assert_match ENTRY_ID_FORMAT, actual
100+
end
101+
93102
def test_xadd_with_invalid_arguments
94103
assert_raises(TypeError) { redis.xadd(nil, {}) }
95104
assert_raises(Redis::CommandError) { redis.xadd('', {}) }
@@ -647,7 +656,7 @@ def test_xclaim_with_invalid_arguments
647656
end
648657

649658
def test_xautoclaim
650-
omit_version(MIN_REDIS_VERSION_XAUTOCLAIM)
659+
omit_version('6.2.0')
651660

652661
redis.xadd('s1', { f: 'v1' }, id: '0-1')
653662
redis.xgroup(:create, 's1', 'g1', '$')
@@ -664,7 +673,7 @@ def test_xautoclaim
664673
end
665674

666675
def test_xautoclaim_with_justid_option
667-
omit_version(MIN_REDIS_VERSION_XAUTOCLAIM)
676+
omit_version('6.2.0')
668677

669678
redis.xadd('s1', { f: 'v1' }, id: '0-1')
670679
redis.xgroup(:create, 's1', 'g1', '$')
@@ -680,7 +689,7 @@ def test_xautoclaim_with_justid_option
680689
end
681690

682691
def test_xautoclaim_with_count_option
683-
omit_version(MIN_REDIS_VERSION_XAUTOCLAIM)
692+
omit_version('6.2.0')
684693

685694
redis.xadd('s1', { f: 'v1' }, id: '0-1')
686695
redis.xgroup(:create, 's1', 'g1', '$')
@@ -697,7 +706,7 @@ def test_xautoclaim_with_count_option
697706
end
698707

699708
def test_xautoclaim_with_larger_interval
700-
omit_version(MIN_REDIS_VERSION_XAUTOCLAIM)
709+
omit_version('6.2.0')
701710

702711
redis.xadd('s1', { f: 'v1' }, id: '0-1')
703712
redis.xgroup(:create, 's1', 'g1', '$')
@@ -713,7 +722,7 @@ def test_xautoclaim_with_larger_interval
713722
end
714723

715724
def test_xautoclaim_with_deleted_entry
716-
omit_version(MIN_REDIS_VERSION_XAUTOCLAIM)
725+
omit_version('6.2.0')
717726

718727
redis.xadd('s1', { f: 'v1' }, id: '0-1')
719728
redis.xgroup(:create, 's1', 'g1', '$')

0 commit comments

Comments
 (0)