File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,25 @@ def read_reply
366
366
end
367
367
end
368
368
369
+ def exec
370
+ # Need to override Kernel#exec.
371
+ call_command ( [ :exec ] )
372
+ end
373
+
374
+ def multi ( &block )
375
+ return super unless block_given?
376
+
377
+ multi
378
+
379
+ begin
380
+ yield
381
+ exec
382
+ rescue Exception => e
383
+ discard
384
+ raise e
385
+ end
386
+ end
387
+
369
388
private
370
389
def get_size ( string )
371
390
string . respond_to? ( :bytesize ) ? string . bytesize : string . size
Original file line number Diff line number Diff line change @@ -665,4 +665,29 @@ def ==(other)
665
665
r . connect_to_server
666
666
end
667
667
668
+ it "should run MULTI without a block" do
669
+ @r . multi
670
+ @r . get ( "key1" ) . should == "QUEUED"
671
+ end
672
+
673
+ it "should run MULTI/EXEC with a block" do
674
+ @r . multi do
675
+ @r . set "key1" , "value1"
676
+ end
677
+
678
+ @r . get ( "key1" ) . should == "value1"
679
+
680
+ begin
681
+ @r . multi do
682
+ @r . set "key2" , "value2"
683
+ raise "Some error"
684
+ @r . set "key3" , "value3"
685
+ end
686
+ rescue
687
+ end
688
+
689
+ @r . get ( "key2" ) . should be_nil
690
+ @r . get ( "key3" ) . should be_nil
691
+ end
692
+
668
693
end
You can’t perform that action at this time.
0 commit comments