|
3 | 3 | module Lint
|
4 | 4 | module Streams
|
5 | 5 | MIN_REDIS_VERSION = '4.9.0'
|
| 6 | + MIN_REDIS_VERSION_XAUTOCLAIM = '6.2.0' |
6 | 7 | ENTRY_ID_FORMAT = /\d+-\d+/.freeze
|
7 | 8 |
|
8 | 9 | def setup
|
@@ -633,6 +634,72 @@ def test_xclaim_with_invalid_arguments
|
633 | 634 | assert_raises(Redis::CommandError) { redis.xclaim('', '', '', '', '') }
|
634 | 635 | end
|
635 | 636 |
|
| 637 | + def test_xautoclaim |
| 638 | + omit_version(MIN_REDIS_VERSION_XAUTOCLAIM) |
| 639 | + |
| 640 | + redis.xadd('s1', { f: 'v1' }, id: '0-1') |
| 641 | + redis.xgroup(:create, 's1', 'g1', '$') |
| 642 | + redis.xadd('s1', { f: 'v2' }, id: '0-2') |
| 643 | + redis.xadd('s1', { f: 'v3' }, id: '0-3') |
| 644 | + redis.xreadgroup('g1', 'c1', 's1', '>') |
| 645 | + sleep 0.01 |
| 646 | + |
| 647 | + actual = redis.xautoclaim('s1', 'g1', 'c2', 10, '0-0') |
| 648 | + |
| 649 | + assert_equal '0-0', actual['next'] |
| 650 | + assert_equal %w(0-2 0-3), actual['entries'].map(&:first) |
| 651 | + assert_equal(%w(v2 v3), actual['entries'].map { |i| i.last['f'] }) |
| 652 | + end |
| 653 | + |
| 654 | + def test_xautoclaim_with_justid_option |
| 655 | + omit_version(MIN_REDIS_VERSION_XAUTOCLAIM) |
| 656 | + |
| 657 | + redis.xadd('s1', { f: 'v1' }, id: '0-1') |
| 658 | + redis.xgroup(:create, 's1', 'g1', '$') |
| 659 | + redis.xadd('s1', { f: 'v2' }, id: '0-2') |
| 660 | + redis.xadd('s1', { f: 'v3' }, id: '0-3') |
| 661 | + redis.xreadgroup('g1', 'c1', 's1', '>') |
| 662 | + sleep 0.01 |
| 663 | + |
| 664 | + actual = redis.xautoclaim('s1', 'g1', 'c2', 10, '0-0', justid: true) |
| 665 | + |
| 666 | + assert_equal '0-0', actual['next'] |
| 667 | + assert_equal %w(0-2 0-3), actual['entries'] |
| 668 | + end |
| 669 | + |
| 670 | + def test_xautoclaim_with_count_option |
| 671 | + omit_version(MIN_REDIS_VERSION_XAUTOCLAIM) |
| 672 | + |
| 673 | + redis.xadd('s1', { f: 'v1' }, id: '0-1') |
| 674 | + redis.xgroup(:create, 's1', 'g1', '$') |
| 675 | + redis.xadd('s1', { f: 'v2' }, id: '0-2') |
| 676 | + redis.xadd('s1', { f: 'v3' }, id: '0-3') |
| 677 | + redis.xreadgroup('g1', 'c1', 's1', '>') |
| 678 | + sleep 0.01 |
| 679 | + |
| 680 | + actual = redis.xautoclaim('s1', 'g1', 'c2', 10, '0-0', count: 1) |
| 681 | + |
| 682 | + assert_equal '0-3', actual['next'] |
| 683 | + assert_equal %w(0-2), actual['entries'].map(&:first) |
| 684 | + assert_equal(%w(v2), actual['entries'].map { |i| i.last['f'] }) |
| 685 | + end |
| 686 | + |
| 687 | + def test_xautoclaim_with_larger_interval |
| 688 | + omit_version(MIN_REDIS_VERSION_XAUTOCLAIM) |
| 689 | + |
| 690 | + redis.xadd('s1', { f: 'v1' }, id: '0-1') |
| 691 | + redis.xgroup(:create, 's1', 'g1', '$') |
| 692 | + redis.xadd('s1', { f: 'v2' }, id: '0-2') |
| 693 | + redis.xadd('s1', { f: 'v3' }, id: '0-3') |
| 694 | + redis.xreadgroup('g1', 'c1', 's1', '>') |
| 695 | + sleep 0.01 |
| 696 | + |
| 697 | + actual = redis.xautoclaim('s1', 'g1', 'c2', 36_000, '0-0') |
| 698 | + |
| 699 | + assert_equal '0-0', actual['next'] |
| 700 | + assert_equal [], actual['entries'] |
| 701 | + end |
| 702 | + |
636 | 703 | def test_xpending
|
637 | 704 | redis.xadd('s1', { f: 'v1' }, id: '0-1')
|
638 | 705 | redis.xgroup(:create, 's1', 'g1', '$')
|
|
0 commit comments