@@ -87,6 +87,46 @@ def test_psubscribe_and_punsubscribe
87
87
assert_equal "s1" , @message
88
88
end
89
89
90
+ def test_pubsub_with_numpat_subcommand
91
+ @subscribed = false
92
+ wire = Wire . new do
93
+ r . psubscribe ( "f*" ) do |on |
94
+ on . psubscribe { |channel , total | @subscribed = true }
95
+ on . pmessage { |pattern , channel , message | r . punsubscribe }
96
+ end
97
+ end
98
+ Wire . pass while !@subscribed
99
+ redis = Redis . new ( OPTIONS )
100
+ numpat_result = redis . pubsub ( :numpat )
101
+
102
+ redis . publish ( "foo" , "s1" )
103
+ wire . join
104
+
105
+ assert_equal redis . pubsub ( :numpat ) , 0
106
+ assert_equal numpat_result , 1
107
+ end
108
+
109
+
110
+ def test_pubsub_with_channels_and_numsub_subcommnads
111
+ @subscribed = false
112
+ wire = Wire . new do
113
+ r . subscribe ( "foo" ) do |on |
114
+ on . subscribe { |channel , total | @subscribed = true }
115
+ on . message { |channel , message | r . unsubscribe }
116
+ end
117
+ end
118
+ Wire . pass while !@subscribed
119
+ redis = Redis . new ( OPTIONS )
120
+ channels_result = redis . pubsub ( :channels )
121
+ numsub_result = redis . pubsub ( :numsub , 'foo' , 'boo' )
122
+
123
+ redis . publish ( "foo" , "s1" )
124
+ wire . join
125
+
126
+ assert_equal channels_result , [ 'foo' ]
127
+ assert_equal numsub_result , [ 'foo' , '1' , 'boo' , '0' ]
128
+ end
129
+
90
130
def test_subscribe_connection_usable_after_raise
91
131
@subscribed = false
92
132
0 commit comments