@@ -10,29 +10,29 @@ def initialize(config = :shared)
1010  end 
1111
1212  def  migrate_all ( key_pattern ) 
13-     each_key_batch_matching ( key_pattern )  do  |keys |
13+     each_key_batch_matching ( key_pattern )  do  |keys ,   pipeline |
1414      keys . each  do  |key |
1515        ids  =  key . scan ( /\d +/ ) . map ( &:to_i ) 
16-         migrate  from : key ,  to : yield ( key ,  *ids ) 
16+         migrate  from : key ,  to : yield ( key ,  *ids ) ,   pipeline :  pipeline 
1717      end 
1818    end 
1919  end 
2020
21-   def  migrate ( from :,  to :) 
21+   def  migrate ( from :,  to :,   pipeline :  nil ) 
2222    namespaced_to  =  Kredis . namespaced_key ( to ) 
2323
2424    if  to . present?  && from  != namespaced_to 
2525      log_migration  "Migrating key #{ from } #{ namespaced_to }   do 
26-         @redis . evalsha  @copy_sha ,  keys : [  from ,  namespaced_to  ] 
26+         ( pipeline  ||  @redis ) . evalsha  @copy_sha ,  keys : [  from ,  namespaced_to  ] 
2727      end 
2828    else 
2929      log_migration  "Skipping blank/unaltered migration key #{ from } #{ to }  
3030    end 
3131  end 
3232
3333  def  delete_all ( key_pattern ) 
34-     each_key_batch_matching ( key_pattern )  do  |keys |
35-       @redis . del  *keys 
34+     each_key_batch_matching ( key_pattern )  do  |keys ,   pipeline |
35+       pipeline . del  *keys 
3636    end 
3737  end 
3838
@@ -43,7 +43,7 @@ def each_key_batch_matching(key_pattern, &block)
4343      cursor  =  "0" 
4444      begin 
4545        cursor ,  keys  =  @redis . scan ( cursor ,  match : key_pattern ,  count : SCAN_BATCH_SIZE ) 
46-         @redis . pipelined  {  yield  keys  } 
46+         @redis . multi  {  | pipeline |  yield  keys ,   pipeline  } 
4747      end  until  cursor  == "0" 
4848    end 
4949
0 commit comments