Skip to content

Commit f9f5444

Browse files
Aaron Israelbyroot
authored andcommitted
[Redis 6.2] Add idle option to XPENDING
Fix: #1125
1 parent 6e90332 commit f9f5444

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Use `MD5` for hashing server nodes in `Redis::Distributed`. This should improve keys distribution among servers. See #1089.
66
- Changed `sadd` and `srem` to now always return an Integer.
77
- Added `sadd?` and `srem?` which always return a Boolean.
8+
- Added support for `IDLE` paramter in `xpending`.
89
- Cluster support has been moved to a `redis_cluster` companion gem.
910
- `select` no longer record the current database. If the client has to reconnect after `select` was used, it will reconnect to the original database.
1011
- Better support Float timeout in blocking commands. See #977.

lib/redis/commands/streams.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ def xautoclaim(key, group, consumer, min_idle_time, start, count: nil, justid: f
331331
# redis.xpending('mystream', 'mygroup')
332332
# @example With range options
333333
# redis.xpending('mystream', 'mygroup', '-', '+', 10)
334+
# @example With range and idle time options
335+
# redis.xpending('mystream', 'mygroup', '-', '+', 10, idle: 9000)
334336
# @example With range and consumer options
335337
# redis.xpending('mystream', 'mygroup', '-', '+', 10, 'consumer1')
336338
#
@@ -341,10 +343,13 @@ def xautoclaim(key, group, consumer, min_idle_time, start, count: nil, justid: f
341343
# @param count [Integer] count the number of entries as limit
342344
# @param consumer [String] the consumer name
343345
#
346+
# @option opts [Integer] :idle pending message minimum idle time in milliseconds
347+
#
344348
# @return [Hash] the summary of pending entries
345349
# @return [Array<Hash>] the pending entries details if options were specified
346-
def xpending(key, group, *args)
350+
def xpending(key, group, *args, idle: nil)
347351
command_args = [:xpending, key, group]
352+
command_args << 'IDLE' << Integer(idle) if idle
348353
case args.size
349354
when 0, 3, 4
350355
command_args.concat(args)

test/lint/streams.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,51 @@ def test_xpending_with_range_options
753753
assert_equal 1, actual[2]['count']
754754
end
755755

756+
def test_xpending_with_range_and_idle_options
757+
target_version "6.2" do
758+
redis.xadd('s1', { f: 'v1' }, id: '0-1')
759+
redis.xgroup(:create, 's1', 'g1', '$')
760+
redis.xadd('s1', { f: 'v2' }, id: '0-2')
761+
redis.xadd('s1', { f: 'v3' }, id: '0-3')
762+
redis.xreadgroup('g1', 'c1', 's1', '>')
763+
764+
actual = redis.xpending('s1', 'g1', '-', '+', 10)
765+
assert_equal 2, actual.size
766+
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
767+
assert_equal 0, actual.size
768+
sleep 0.1
769+
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
770+
assert_equal 2, actual.size
771+
772+
redis.xadd('s1', { f: 'v4' }, id: '0-4')
773+
redis.xreadgroup('g1', 'c2', 's1', '>')
774+
775+
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 1000)
776+
assert_equal 0, actual.size
777+
778+
actual = redis.xpending('s1', 'g1', '-', '+', 10)
779+
assert_equal 3, actual.size
780+
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
781+
assert_equal 2, actual.size
782+
sleep 0.01
783+
actual = redis.xpending('s1', 'g1', '-', '+', 10, idle: 10)
784+
assert_equal 3, actual.size
785+
786+
assert_equal '0-2', actual[0]['entry_id']
787+
assert_equal 'c1', actual[0]['consumer']
788+
assert_equal true, actual[0]['elapsed'] >= 0
789+
assert_equal 1, actual[0]['count']
790+
assert_equal '0-3', actual[1]['entry_id']
791+
assert_equal 'c1', actual[1]['consumer']
792+
assert_equal true, actual[1]['elapsed'] >= 0
793+
assert_equal 1, actual[1]['count']
794+
assert_equal '0-4', actual[2]['entry_id']
795+
assert_equal 'c2', actual[2]['consumer']
796+
assert_equal true, actual[2]['elapsed'] >= 0
797+
assert_equal 1, actual[2]['count']
798+
end
799+
end
800+
756801
def test_xpending_with_range_and_consumer_options
757802
redis.xadd('s1', { f: 'v1' }, id: '0-1')
758803
redis.xgroup(:create, 's1', 'g1', '$')

0 commit comments

Comments
 (0)