@@ -10,29 +10,29 @@ def initialize(config = :shared)
10
10
end
11
11
12
12
def migrate_all ( key_pattern )
13
- each_key_batch_matching ( key_pattern ) do |keys |
13
+ each_key_batch_matching ( key_pattern ) do |keys , pipeline |
14
14
keys . each do |key |
15
15
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
17
17
end
18
18
end
19
19
end
20
20
21
- def migrate ( from :, to :)
21
+ def migrate ( from :, to :, pipeline : nil )
22
22
namespaced_to = Kredis . namespaced_key ( to )
23
23
24
24
if to . present? && from != namespaced_to
25
25
log_migration "Migrating key #{ from } to #{ namespaced_to } " do
26
- @redis . evalsha @copy_sha , keys : [ from , namespaced_to ]
26
+ ( pipeline || @redis ) . evalsha @copy_sha , keys : [ from , namespaced_to ]
27
27
end
28
28
else
29
29
log_migration "Skipping blank/unaltered migration key #{ from } → #{ to } "
30
30
end
31
31
end
32
32
33
33
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
36
36
end
37
37
end
38
38
@@ -43,7 +43,7 @@ def each_key_batch_matching(key_pattern, &block)
43
43
cursor = "0"
44
44
begin
45
45
cursor , keys = @redis . scan ( cursor , match : key_pattern , count : SCAN_BATCH_SIZE )
46
- @redis . pipelined { yield keys }
46
+ @redis . multi { | pipeline | yield keys , pipeline }
47
47
end until cursor == "0"
48
48
end
49
49
0 commit comments