Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redis 6.2] Add idle option to XPENDING #1125

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 6 additions & 1 deletion lib/redis/commands/streams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ def xautoclaim(key, group, consumer, min_idle_time, start, count: nil, justid: f
# redis.xpending('mystream', 'mygroup')
# @example With range options
# redis.xpending('mystream', 'mygroup', '-', '+', 10)
# @example With range and idle time options
# redis.xpending('mystream', 'mygroup', '-', '+', 10, idle: 9000)
# @example With range and consumer options
# redis.xpending('mystream', 'mygroup', '-', '+', 10, 'consumer1')
#
Expand All @@ -344,10 +346,13 @@ def xautoclaim(key, group, consumer, min_idle_time, start, count: nil, justid: f
# @param count [Integer] count the number of entries as limit
# @param consumer [String] the consumer name
#
# @option opts [Integer] :idle pending message minimum idle time in milliseconds
#
# @return [Hash] the summary of pending entries
# @return [Array<Hash>] the pending entries details if options were specified
def xpending(key, group, *args)
def xpending(key, group, *args, idle: nil)
command_args = [:xpending, key, group]
command_args << 'IDLE' << Integer(idle) if idle
case args.size
when 0, 3, 4
command_args.concat(args)
Expand Down
43 changes: 43 additions & 0 deletions test/lint/streams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,49 @@ def test_xpending_with_range_options
assert_equal 1, actual[2]['count']
end

def test_xpending_with_range_and_idle_options
redis.xadd('s1', { f: 'v1' }, id: '0-1')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test needs to be wrapped in a target_version "6.2" do block.

redis.xgroup(:create, 's1', 'g1', '$')
redis.xadd('s1', { f: 'v2' }, id: '0-2')
redis.xadd('s1', { f: 'v3' }, id: '0-3')
redis.xreadgroup('g1', 'c1', 's1', '>')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop is unhappy

Offenses:

test/lint/streams.rb:761:1: C: [Correctable] Layout/TrailingWhitespace: Trailing whitespace detected.

actual = redis.xpending('s1', 'g1', '-', '+', 10)
assert_equal 2, actual.size
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
assert_equal 0, actual.size
sleep 0.1
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
assert_equal 2, actual.size

redis.xadd('s1', { f: 'v4' }, id: '0-4')
redis.xreadgroup('g1', 'c2', 's1', '>')

actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 1000)
assert_equal 0, actual.size

actual = redis.xpending('s1', 'g1', '-', '+', 10)
assert_equal 3, actual.size
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
assert_equal 2, actual.size
sleep 0.01
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
assert_equal 3, actual.size

assert_equal '0-2', actual[0]['entry_id']
assert_equal 'c1', actual[0]['consumer']
assert_equal true, actual[0]['elapsed'] >= 0
assert_equal 1, actual[0]['count']
assert_equal '0-3', actual[1]['entry_id']
assert_equal 'c1', actual[1]['consumer']
assert_equal true, actual[1]['elapsed'] >= 0
assert_equal 1, actual[1]['count']
assert_equal '0-4', actual[2]['entry_id']
assert_equal 'c2', actual[2]['consumer']
assert_equal true, actual[2]['elapsed'] >= 0
assert_equal 1, actual[2]['count']
end

def test_xpending_with_range_and_consumer_options
redis.xadd('s1', { f: 'v1' }, id: '0-1')
redis.xgroup(:create, 's1', 'g1', '$')
Expand Down