@@ -187,6 +187,61 @@ def test_pubsub_without_subscription
187
187
pubsub . close
188
188
end
189
189
190
+ def test_transaction_with_single_key
191
+ want = [ 'OK' , 1 , 2 , '2' ]
192
+ got = @client . multi do |t |
193
+ t . call ( 'SET' , 'counter' , '0' )
194
+ t . call ( 'INCR' , 'counter' )
195
+ t . call ( 'INCR' , 'counter' )
196
+ t . call ( 'GET' , 'counter' )
197
+ end
198
+
199
+ assert_equal ( want , got )
200
+ end
201
+
202
+ def test_transaction_with_multiple_key
203
+ assert_raises ( ::RedisClient ::Cluster ::Transaction ::ConsistencyError ) do
204
+ @client . multi do |t |
205
+ t . call ( 'SET' , 'key1' , '1' )
206
+ t . call ( 'SET' , 'key2' , '2' )
207
+ t . call ( 'SET' , 'key3' , '3' )
208
+ end
209
+ end
210
+
211
+ ( 1 ..3 ) . each do |i |
212
+ assert_nil ( @client . call ( 'GET' , "key#{ i } " ) )
213
+ end
214
+ end
215
+
216
+ def test_transaction_with_empty_block
217
+ assert_raises ( ArgumentError ) { @client . multi { } }
218
+ end
219
+
220
+ def test_transaction_with_hashtag
221
+ want = [ 'OK' , 'OK' , %w[ 1 2 3 4 ] ]
222
+ got = @client . multi do |t |
223
+ t . call ( 'MSET' , '{key}1' , '1' , '{key}2' , '2' )
224
+ t . call ( 'MSET' , '{key}3' , '3' , '{key}4' , '4' )
225
+ t . call ( 'MGET' , '{key}1' , '{key}2' , '{key}3' , '{key}4' )
226
+ end
227
+
228
+ assert_equal ( want , got )
229
+ end
230
+
231
+ def test_transaction_without_hashtag
232
+ assert_raises ( ::RedisClient ::Cluster ::Transaction ::ConsistencyError ) do
233
+ @client . multi do |t |
234
+ t . call ( 'MSET' , 'key1' , '1' , 'key2' , '2' )
235
+ t . call ( 'MSET' , 'key3' , '3' , 'key4' , '4' )
236
+ t . call ( 'MGET' , 'key1' , 'key2' , 'key3' , 'key4' )
237
+ end
238
+ end
239
+
240
+ ( 1 ..4 ) . each do |i |
241
+ assert_nil ( @client . call ( 'GET' , "key#{ i } " ) )
242
+ end
243
+ end
244
+
190
245
def test_pubsub_with_wrong_command
191
246
pubsub = @client . pubsub
192
247
assert_nil ( pubsub . call ( 'SUBWAY' ) )
0 commit comments