@@ -711,6 +711,47 @@ def test_other_pubsub_commands
711
711
ps . close
712
712
end
713
713
714
+ def test_stream_commands
715
+ @client . call ( 'xadd' , '{stream}1' , '*' , 'mesage' , 'foo' )
716
+ @client . call ( 'xadd' , '{stream}1' , '*' , 'mesage' , 'bar' )
717
+ @client . call ( 'xadd' , '{stream}2' , '*' , 'mesage' , 'baz' )
718
+ @client . call ( 'xadd' , '{stream}2' , '*' , 'mesage' , 'zap' )
719
+ wait_for_replication
720
+
721
+ consumer = new_test_client
722
+ got = consumer . call ( 'xread' , 'streams' , '{stream}1' , '{stream}2' , '0' , '0' )
723
+ consumer . close
724
+
725
+ got = got . to_h if TEST_REDIS_MAJOR_VERSION < 6
726
+
727
+ assert_equal ( 'foo' , got . fetch ( '{stream}1' ) [ 0 ] [ 1 ] [ 1 ] )
728
+ assert_equal ( 'bar' , got . fetch ( '{stream}1' ) [ 1 ] [ 1 ] [ 1 ] )
729
+ assert_equal ( 'baz' , got . fetch ( '{stream}2' ) [ 0 ] [ 1 ] [ 1 ] )
730
+ assert_equal ( 'zap' , got . fetch ( '{stream}2' ) [ 1 ] [ 1 ] [ 1 ] )
731
+ end
732
+
733
+ def test_stream_group_commands
734
+ @client . call ( 'xadd' , '{stream}1' , '*' , 'task' , 'data1' )
735
+ @client . call ( 'xadd' , '{stream}1' , '*' , 'task' , 'data2' )
736
+ @client . call ( 'xgroup' , 'create' , '{stream}1' , 'worker' , '0' )
737
+ wait_for_replication
738
+
739
+ consumer1 = new_test_client
740
+ consumer2 = new_test_client
741
+ got1 = consumer1 . call ( 'xreadgroup' , 'group' , 'worker' , 'consumer1' , 'count' , '1' , 'streams' , '{stream}1' , '>' )
742
+ got2 = consumer2 . call ( 'xreadgroup' , 'group' , 'worker' , 'consumer2' , 'count' , '1' , 'streams' , '{stream}1' , '>' )
743
+ consumer1 . close
744
+ consumer2 . close
745
+
746
+ if TEST_REDIS_MAJOR_VERSION < 6
747
+ got1 = got1 . to_h
748
+ got2 = got2 . to_h
749
+ end
750
+
751
+ assert_equal ( 'data1' , got1 . fetch ( '{stream}1' ) [ 0 ] [ 1 ] [ 1 ] )
752
+ assert_equal ( 'data2' , got2 . fetch ( '{stream}1' ) [ 0 ] [ 1 ] [ 1 ] )
753
+ end
754
+
714
755
def test_with_method
715
756
assert_raises ( NotImplementedError ) { @client . with }
716
757
end
0 commit comments